Skip to content

Conversation

@Mojackhak
Copy link
Contributor

@Mojackhak Mojackhak commented Jun 13, 2025

Reference issue (if any)

Fixes #6686
Fixes #13285

What does this implement/fix?

This patch modifies the _rgb function in mne/viz/evoked.py to reduce the intensity of overly light RGB colors that can occur when spatial_colors=True is used in PSD plots. Specifically, it checks whether the sum of RGB components is above a threshold (2.5) and reduces the brightness to improve trace visibility.

This issue was previously discussed in Discourse thread #6572, and this fix follows the workaround suggested by @bboyth, which has been confirmed to work in MNE 1.9.0 by multiple users.

Additional information

None

@welcome
Copy link

welcome bot commented Jun 13, 2025

Hello! 👋 Thanks for opening your first pull request here! ❤️ We will try to get back to you soon. 🚴

@larsoner
Copy link
Member

Can you add a doc/changes/devel/13286.bugfix.rst with your change using the :newcontrib: directive (see other examples in the doc/changes/devel folder)?

And then can you make some trivial change to https://github.com/mne-tools/mne-python/blob/main/tutorials/evoked/20_visualize_evoked.py ? Any trivial change should work (e.g., changing whitespace) as it will make CircleCI rerender the example so we can see if it changes

@Mojackhak
Copy link
Contributor Author

thanks for your patience! I’ve pushed the updates.

@larsoner
Copy link
Member

One more thing from above ☝️

And then can you make some trivial change to https://github.com/mne-tools/mne-python/blob/main/tutorials/evoked/20_visualize_evoked.py ? Any trivial change should work (e.g., changing whitespace) as it will make CircleCI rerender the example so we can see if it changes

@Mojackhak
Copy link
Contributor Author

sorry for that. I've pushed another update

@larsoner
Copy link
Member

I looked at the example and the images didn't change, which I guess is okay since none of those were really invisible. Adapting the example from one of the issues above:

import mne
from mne.datasets import sample
data_path = sample.data_path()
raw_fname = data_path / 'MEG/sample/sample_audvis_raw.fif'
raw = mne.io.read_raw_fif(raw_fname, preload=True)
raw.drop_channels(raw.info["ch_names"][:315])
raw.drop_channels(raw.info["ch_names"][4:])
raw.info["bads"] = ['EEG 003', 'EEG 004']
raw.plot_psd(spatial_colors=True, picks=range(4), exclude=())

I do see one channel that was hard to see get a bit darker

main PR
Screenshot From 2025-06-17 11-58-18 Screenshot From 2025-06-17 11-59-53

In the future we might consider using some other smoother transformation of all lightness values (like a sigmoid or even just a linear rescaling) rather than a threshold-based one since this one could lead to color collisions but this already seems like a usability improvement.

So I think this is good to go, marking for merge-when-green, thanks in advance @Mojackhak !

@larsoner larsoner enabled auto-merge (squash) June 17, 2025 16:03
@larsoner larsoner merged commit 8df70ae into mne-tools:main Jun 17, 2025
32 checks passed
@welcome
Copy link

welcome bot commented Jun 17, 2025

🎉 Congrats on merging your first pull request! 🥳 Looking forward to seeing more from you in the future! 💪

@Mojackhak
Copy link
Contributor Author

Thanks for double-checking and merging! 🙌

larsoner added a commit to larsoner/mne-python that referenced this pull request Jun 26, 2025
* upstream/main: (55 commits)
  doc: fix rendering typo rst docstr (mne-tools#13301)
  DOC: fix docstrs around layout functions (mne-tools#13300)
  MAINT: Fix doc build failure due to deprecation (mne-tools#13299)
  Birthday input cast to datetime.date (mne-tools#13284)
  DOC: fix missing space, use f-strings, structure->object (mne-tools#13291)
  [pre-commit.ci] pre-commit autoupdate (mne-tools#13290)
  ENH: channel_indices_by_type now has an exclude param (mne-tools#13293)
  Proj id and proj name access (mne-tools#13261)
  Fix: nearly invisible traces with spatial_colors=True (mne-tools#13286)
  [pre-commit.ci] pre-commit autoupdate (mne-tools#13283)
  Bump autofix-ci/action from 551dded8c6cc8a1054039c8bc0b8b48c51dfc6ef to 635ffb0c9798bd160680f18fd73371e355b85f27 in the actions group (mne-tools#13282)
  fix Maxwell bads filtering (mne-tools#13280)
  fix actionable linkcheck errors (mne-tools#13273)
  MAINT: Use radius keyword with PyVista tube (mne-tools#13277)
  BUG: Fix bug with simulating head pos and BEM (mne-tools#13276)
  [pre-commit.ci] pre-commit autoupdate (mne-tools#13274)
  MAINT: Update code credit (mne-tools#13267)
  Annotations extras (mne-tools#13228)
  Tidy up the directory reading (mne-tools#13268)
  FIX, DOC: Drop bad channel in 10_publication_figure.py (mne-tools#13266)
  ...
WouterKroot pushed a commit to WouterKroot/mne-python that referenced this pull request Aug 13, 2025
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
zEdS15B3GCwq pushed a commit to zEdS15B3GCwq/mne-python that referenced this pull request Aug 25, 2025
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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.

Some channels in PSD plot colors nearly invisible with spatial_colors=True in v1.9.0 Avoid almost white colors in plots with spatial_colors=True

2 participants