Skip to content
Merged
Show file tree
Hide file tree
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 doc/changes/latest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ Enhancements

- Speed up :meth:`mne.decoding.TimeDelayingRidge.predict` by switching to FFT-based convolution (:gh:`9458` by `Ross Maddox`_)

- Show multiple colors and linestyles for excluded components with :class:`mne.Evoked` in :meth:`mne.preprocessing.ICA.plot_sources` (:gh:`9444` by `Martin Schulz`_)

Bugs
~~~~
- Fix bug with :meth:`mne.Epochs.crop` and :meth:`mne.Evoked.crop` when ``include_tmax=False``, where the last sample was always cut off, even when ``tmax > epo.times[-1]`` (:gh:`9378` **by new contributor** |Jan Sosulski|_)
Expand Down
38 changes: 19 additions & 19 deletions mne/viz/ica.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,29 +574,29 @@ def _plot_ica_sources_evoked(evoked, picks, exclude, title, show, ica,
exclude_labels.append(line_label)
else:
exclude_labels.append(None)

label_props = [('k', '-') if lb is None else ('r', '-') for lb in
exclude_labels]
styles = ['-', '--', ':', '-.']
if labels is not None:
# compute colors only based on label categories
# differentiate categories by linestyle and components by color
col_lbs = [it for it in exclude_labels if it is not None]
cmap = plt.get_cmap('tab10', len(col_lbs))
unique_labels = {k.split(' - ')[1] for k in exclude_labels if k}
label_colors = plt.cm.rainbow(np.linspace(0, 1, len(unique_labels)))
label_colors = dict(zip(unique_labels, label_colors))
else:
label_colors = {k: 'red' for k in exclude_labels}
# Determine up to 4 different styles for n categories
cat_styles = dict(zip(unique_labels,
map(lambda ux: styles[int(ux % len(styles))],
range(len(unique_labels)))))
for lb_idx, lb in enumerate(exclude_labels):
if lb is not None:
color = cmap(col_lbs.index(lb))
style = cat_styles[lb[lb.find(' - ') + 3:]]
label_props[lb_idx] = (color, style)

for exc_label, ii in zip(exclude_labels, picks):
if exc_label is not None:
# create look up for color ...
if ' - ' in exc_label:
key = exc_label.split(' - ')[1]
else:
key = exc_label
color = label_colors[key]
# ... but display component number too
lines.extend(ax.plot(times, evoked.data[ii].T, picker=True,
zorder=2, color=color, label=exc_label))
else:
lines.extend(ax.plot(times, evoked.data[ii].T, picker=True,
color='k', zorder=1))
color, style = label_props[ii]
lines.extend(ax.plot(times, evoked.data[ii].T, picker=True,
zorder=2, color=color, linestyle=style,
label=exc_label))
lines[-1].set_pickradius(3.)

ax.set(title=title, xlim=times[[0, -1]], xlabel='Time (ms)', ylabel='(NA)')
Expand Down
2 changes: 1 addition & 1 deletion tutorials/preprocessing/40_artifact_correction_ica.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@
# This example is computationally intensive, so it might take a few minutes
# to complete.
#
# Read and preprocess the data. Preprocessing consists of:
# After reading the data, preprocessing consists of:
#
# - MEG channel selection
# - 1-30 Hz band-pass filter
Expand Down