Skip to content

Commit 31a7326

Browse files
FIX: pass cmap name string not tuple to interactive topomap slider kwargs (#14039)
1 parent 9d71dd0 commit 31a7326

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

mne/viz/tests/test_topomap.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,25 @@ def test_plot_evoked_topomap_border():
353353
assert_almost_equal(img_data[idx, idx], data[0], decimal=9)
354354

355355

356+
def test_plot_topomap_interactive_slider_cmap():
357+
"""Regression test: moving the time slider must not raise KeyError on cmap.
358+
359+
gh-14038: group_cmaps stored full (name, draggable) tuples but the slider
360+
callback passed the tuple as the cmap kwarg, causing a KeyError in
361+
matplotlib's colormap registry.
362+
"""
363+
evoked = read_evokeds(evoked_fname, "Left Auditory", baseline=(None, 0))
364+
evoked.pick("mag")
365+
fig = evoked.plot_topomap(times="interactive", **fast_test)
366+
# Trigger the slider callback — this crashed before the fix.
367+
# The slider axes is not necessarily fig.axes[-1] (colorbar may follow it),
368+
# so find it by looking for the axes that has a .slider attribute.
369+
slider_ax = next(ax for ax in fig.axes if hasattr(ax, "slider"))
370+
slider_ax.slider.set_val(evoked.times[len(evoked.times) // 2])
371+
# Verify the topomap was redrawn (not blank) — would fail with double-scaling
372+
assert len(fig.axes[0].images) > 0
373+
374+
356375
@pytest.mark.slowtest
357376
def test_plot_topomap_basic():
358377
"""Test basics of topomap plotting."""

mne/viz/topomap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2724,7 +2724,7 @@ def _plot_evoked_topomap(
27242724
if interactive:
27252725
# Add a slider to the figure and start publishing and subscribing to time_change
27262726
# events.
2727-
kwargs.update(vlim=group_vlims[0], cmap=group_cmaps[0])
2727+
kwargs.update(vlim=group_vlims[0], cmap=group_cmaps[0][0])
27282728
axes.append(fig.add_subplot(gs[1]))
27292729
slider = Slider(
27302730
axes[-1],

0 commit comments

Comments
 (0)