Skip to content

Fix bugs with dark mode panels - #14109

Merged
wmvanvliet merged 2 commits into
mne-tools:mainfrom
larsoner:dark
Aug 4, 2026
Merged

Fix bugs with dark mode panels#14109
wmvanvliet merged 2 commits into
mne-tools:mainfrom
larsoner:dark

Conversation

@larsoner

Copy link
Copy Markdown
Member

#14108 unsurfaced that we don't consistently or correctly honor dark mode in our subpanels. This PR fixes it:

from pathlib import Path
import matplotlib.pyplot as plt
import mne

mne.viz.set_browser_backend("matplotlib")
fname = Path(mne.__file__).parent / "io" / "tests" / "data" / "test_raw.fif"
raw = mne.io.read_raw_fif(fname, verbose="error").crop(0, 5).pick("mag").load_data()
raw.set_annotations(mne.Annotations([1.0], [0.5], ["bad_x"]))

fig = raw.plot(group_by="selection", theme="dark", show=False)
for key in "?ja":  # help, SSP projectors, annotations
    fig._fake_keypress(key)

In this PR gives

Screenshot 2026-07-27 at 4 42 51 PM

Don't think a test is needed for this one but could add if needed. Drafted changes with Opus 4.8.

Comment thread mne/viz/_mpl_figure.py Outdated
"""Check whether a background color calls for light foreground colors."""
# mne-qt-browser decides this via oklab lightness; HSV value agrees with it across
# the range of backgrounds we care about
return rgb_to_hsv(*_to_rgb(color))[2] < 0.5

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we have a few other places around the codebase (search for dark) where we do almost the same thing. Could those places also call this function?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ooohh good call, I'll look!

@larsoner
larsoner force-pushed the dark branch 3 times, most recently from 0a4ab10 to 85fc788 Compare August 4, 2026 13:35
@larsoner

larsoner commented Aug 4, 2026

Copy link
Copy Markdown
Member Author

Turned out there were a number of places we could unify. I also updated it to use Oklab color like in mne-qt-browser (better than CIELab). Okay to merge @wmvanvliet ?

@wmvanvliet
wmvanvliet enabled auto-merge (squash) August 4, 2026 13:44
@wmvanvliet
wmvanvliet merged commit 35019b1 into mne-tools:main Aug 4, 2026
29 checks passed
larsoner added a commit to larsoner/mne-python that referenced this pull request Aug 4, 2026
* upstream/main: (35 commits)
  Fix bug with coreg scaling (mne-tools#14132)
  MAINT: Update code credit (mne-tools#14131)
  Fix bugs with dark mode panels (mne-tools#14109)
  Improve code credit workflow (mne-tools#14120)
  Align _AbstractRenderer.tube with the PyVista implementation (mne-tools#14125)
  Assign instead of compare when marking explicit zeros in spatio_temporal_dist_adjacency (mne-tools#14124)
  MAINT: Update pre-commit hook versions (mne-tools#14122)
  MAINT: Update dependency specifiers (mne-tools#14121)
  fix: correct typo in comment (mne-tools#14117)
  [dependabot]: Bump the actions group with 2 updates (mne-tools#14123)
  Fix` read_raw_eyelink()` failure when recording blocks are empty or starting with empty values (mne-tools#13571)
  ENH: Add `event_key` parameter to `read_raw_egi` for MFF event metadata (mne-tools#14086)
  fix for scipy sparse deprecations (mne-tools#14118)
  Fix notch spectrum fit (mne-tools#14116)
  Speed up notch filter spectrum fit (mne-tools#14114)
  fix MNE-RT links and update roadmap (mne-tools#14096)
  Clarify `docdict["filter_length_notch"]` (mne-tools#14113)
  Refactor test_plot_alignment_basic() (mne-tools#13472)
  BUG: Cleanup cHPI filtering using smooth interpolation (mne-tools#14112)
  Use redirector app (mne-tools#14111)
  ...

# Conflicts:
#	mne/tests/test_filter.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants