FIX: Set zorder for y-axis spine in plot_evoked (#13492)
Here is a perfect description for your Pull Request (PR) based on the fix you implemented, filling out the expected MNE-Python layout:
Reference issue (if any) Fixes #13492.
What does this implement/fix? This PR fixes a plotting regression where the Y-axis spine (the vertical line) was drawn behind the plotted data lines, causing it to be obscured, especially by the Global Field Power (GFP) or channel traces in butterfly plots.
The fix involves explicitly setting a high Matplotlib zorder for the left axis spine in mne.viz._plot_lines:
A single line was added: ax.spines['left'].set_zorder(10)
This ensures the spine is always rendered on top of the data lines, which typically have a default zorder of 1-3.
Hey @mohit-malpote I dont think this fixes the issue? :
I ran this tutorial: https://mne.tools/stable/auto_tutorials/evoked/30_eeg_erp.html#sphx-glr-auto-tutorials-evoked-30-eeg-erp-py
By running this command from the mne-python repository root directory (after checking out this PR's branch):
ipython -i tutorials/evoked/30_eeg_erp.py
I have made a final push to the branch using a fixed, high z-order (50) for the left axis spine, as the dynamic z-order (i.e. solution of @mistraube ) calculation was also unsuccessful.
The plot still fails the visual check on my end (the spine remains hidden behind the traces). This indicates that a final axis styling function, likely run outside of the primary plotting loop, is overriding the zorder property.
Is your screenshot from the try with fixed zorder 50? Would make sence to me since only some (of the 59) channels are plotted above the axis.
For me this works:
ax.spines[:].set_zorder(max(l.get_zorder() for l in ax.get_lines()) + 1)
I have verified the fix locally against the tutorial, and it is now working correctly! The vertical Y-axis spine is clearly visible on top of all the data traces.
I have pushed the final commit implementing the robust z-order fix.
Thanks again to @mistraube for providing the key insight for the dynamic zorder calculation!
@mohit-malpote are you still interested in working on this?