Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mne/viz/evoked.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,8 @@ def _plot_lines(
# Put back the y limits as fill_betweenx messes them up
ax.set_ylim(this_ylim)

ax.spines[:].set_zorder(max(l.get_zorder() for l in ax.get_lines()) + 1)

Comment on lines +811 to +812
Copy link
Contributor

@scott-huberty scott-huberty Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ax.spines[:].set_zorder(max(l.get_zorder() for l in ax.get_lines()) + 1)
# Ensure the axis spines are drawn above all Line2D artists
max_zorder = max((line.get_zorder() for line in ax.get_lines()), default=0) + 1
ax.spines[:].set_zorder(max_zorder)
  1. Locally, Ruff complains about l being an ambiguous variable name (and I agree).
  2. I split @mistraube 's suggestion into 2 lines to make the code a little more verbose, and added a code comment as hint to other devs.
  3. the max(..., default=0) is just a little defensive programming to guard against a case where there are no Line2D artists to iterate through, which could throw an error. We may never actually ever hit that case in the wild, but better safe than sorry.

@mohit-malpote is it clear for you why @mistraube 's approach is preferable to hard coding a z-order like 10 or even 50? The upshot is that each of these Line2D artists correspond to one channel on the plot. A single, hardcoded z-order won't work for all use-cases (Some EEG nets have 256 or more channels!).. So computing the maximum z-order dynamically is the way to go.

lines.append(line_list)

if selectable:
Expand Down
Loading