|
7 | 7 | from copy import deepcopy |
8 | 8 | from pathlib import Path |
9 | 9 |
|
| 10 | +import matplotlib.colors as mcolors |
10 | 11 | import matplotlib.pyplot as plt |
11 | 12 | import numpy as np |
12 | 13 | import pytest |
@@ -317,6 +318,31 @@ def test_scale_bar(browser_backend): |
317 | 318 | bar_lims = bar.get_ydata() |
318 | 319 | assert_allclose(y_lims, bar_lims, atol=1e-4) |
319 | 320 |
|
| 321 | + # Per-channel color overrides via channel names (matplotlib only). |
| 322 | + if ismpl: |
| 323 | + sfreq = 100.0 |
| 324 | + ch_names = ["SFG, Left", "SFG, Right", "MFG, Left"] |
| 325 | + info = create_info(ch_names=ch_names, sfreq=sfreq, ch_types="eeg") |
| 326 | + data = np.zeros((len(ch_names), int(sfreq))) # 1 second of zeros |
| 327 | + raw2 = RawArray(data, info) |
| 328 | + |
| 329 | + color = {"eeg": "k", "SFG, Left": "red"} |
| 330 | + browser_backend._close_all() |
| 331 | + fig2 = plot_raw(raw2, color=color, show=False) |
| 332 | + |
| 333 | + # ch_colors stores the "good" (non-bad) colors, in visible channel order |
| 334 | + assert fig2.mne.ch_colors[0] == "red" |
| 335 | + assert fig2.mne.ch_colors[1] == "k" |
| 336 | + assert fig2.mne.ch_colors[2] == "k" |
| 337 | + |
| 338 | + # check colours on the plot are also correct |
| 339 | + for trace, ch_color in zip(fig2.mne.traces, fig2.mne.ch_colors): |
| 340 | + assert np.allclose( |
| 341 | + mcolors.to_rgba(trace.get_color()), mcolors.to_rgba(ch_color) |
| 342 | + ), f"Expected {ch_color}, got {trace.get_color()}" |
| 343 | + |
| 344 | + browser_backend._close_all() |
| 345 | + |
320 | 346 |
|
321 | 347 | def test_plot_raw_selection(raw, browser_backend): |
322 | 348 | """Test selection mode of plot_raw().""" |
|
0 commit comments