mne-python icon indicating copy to clipboard operation
mne-python copied to clipboard

FIX: Set zorder for y-axis spine in plot_evoked (#13492)

Open mohit-malpote opened this issue 1 month ago • 3 comments

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.

mohit-malpote avatar Nov 22 '25 04:11 mohit-malpote

Hey @mohit-malpote I dont think this fixes the issue? :

Screenshot 2025-11-21 at 9 00 33 PM

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

scott-huberty avatar Nov 22 '25 05:11 scott-huberty

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)
Bildschirmfoto_20251122_190245

mistraube avatar Nov 22 '25 18:11 mistraube

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!

Screenshot from 2025-11-23 10-53-30

mohit-malpote avatar Nov 23 '25 05:11 mohit-malpote

@mohit-malpote are you still interested in working on this?

mistraube avatar Dec 15 '25 11:12 mistraube