Skip to content
Open
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
1 change: 1 addition & 0 deletions doc/changes/dev/13756.newfeature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added ``cmap`` parameter to ``Evoked.animate_topomap`` to allow user-specified colormaps., by :newcontrib:`Hansuja Budhiraja`.
9 changes: 8 additions & 1 deletion mne/evoked.py
Original file line number Diff line number Diff line change
Expand Up @@ -797,12 +797,13 @@ def animate_topomap(
ch_type=None,
times=None,
frame_rate=None,
*,
cmap=None,
butterfly=False,
blit=True,
show=True,
time_unit="s",
sphere=None,
*,
image_interp=_INTERPOLATION_DEFAULT,
extrapolate=_EXTRAPOLATE_DEFAULT,
vmin=None,
Expand All @@ -829,6 +830,11 @@ def animate_topomap(
frame_rate : int | None
Frame rate for the animation in Hz. If None,
frame rate = sfreq / 10. Defaults to None.
cmap : matplotlib colormap | None
Colormap to use. If None, 'Reds' is used for all positive data,
otherwise defaults to 'RdBu_r'.

.. versionadded:: 1.12.0
butterfly : bool
Whether to plot the data as butterfly plot under the topomap.
Defaults to False.
Expand Down Expand Up @@ -880,6 +886,7 @@ def animate_topomap(
vmin=vmin,
vmax=vmax,
verbose=verbose,
cmap=cmap,
)

def as_type(self, ch_type="grad", mode="fast"):
Expand Down
10 changes: 8 additions & 2 deletions mne/viz/tests/test_topomap.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,18 @@ def test_plot_topomap_animation(capsys):
evoked = read_evokeds(evoked_fname, "Left Auditory", baseline=(None, 0))

# Test animation
_, anim = evoked.animate_topomap(
ch_type="grad", times=[0, 0.1], butterfly=False, time_unit="s", verbose="debug"
fig, anim = evoked.animate_topomap(
ch_type="grad",
times=[0, 0.1],
cmap="viridis",
butterfly=False,
time_unit="s",
verbose="debug",
)
anim._func(1) # _animate has to be tested separately on 'Agg' backend.
out, _ = capsys.readouterr()
assert "extrapolation mode local to 0" in out
assert fig.axes[0].images[0].get_cmap().name == "viridis"


def test_plot_topomap_animation_csd(capsys):
Expand Down
6 changes: 5 additions & 1 deletion mne/viz/topomap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3149,6 +3149,7 @@ def _init_anim(
merge_channels,
sphere,
ch_type,
cmap,
image_interp,
extrapolate,
verbose,
Expand All @@ -3174,7 +3175,8 @@ def _init_anim(

data, _ = _merge_ch_data(data, "grad", [])
norm = True if np.min(data) > 0 else False
cmap = "Reds" if norm else "RdBu_r"
if cmap is None:
cmap = "Reds" if norm else "RdBu_r"

vmin, vmax = _setup_vmin_vmax(data, vmin, vmax, norm)

Expand Down Expand Up @@ -3324,6 +3326,7 @@ def _key_press(event, params):
def _topomap_animation(
evoked,
ch_type,
cmap,
times,
frame_rate,
butterfly,
Expand Down Expand Up @@ -3407,6 +3410,7 @@ def _topomap_animation(
merge_channels=merge_channels,
sphere=sphere,
ch_type=ch_type,
cmap=cmap,
image_interp=image_interp,
extrapolate=extrapolate,
verbose=verbose,
Expand Down
Loading