Skip to content

Commit 537d7fe

Browse files
authored
ENH: Improve report plotting and animate_topomap (#13905)
1 parent 1ec8f7b commit 537d7fe

9 files changed

Lines changed: 621 additions & 473 deletions

File tree

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ jobs:
222222
keys:
223223
- data-cache-ds004388
224224
- run:
225-
name: Get data
225+
name: Get data and triage examples to run
226226
# This limit could be increased, but this is helpful for finding slow ones
227227
# (even ~2GB datasets should be downloadable in this time from good
228228
# providers)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
In :meth:`mne.Evoked.animate_topomap` the ``vmin`` and ``vmax`` keyword arguments have been deprecated in favor of ``vlim``, by `Eric Larson`_.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Improved :class:`mne.Report` by:
2+
3+
- Using ``"agg"`` backend for 2D plots to avoid windows unnecessarily popping up
4+
- Improving :meth:`~mne.Report.add_stc` by using direct capture of brain images, allowing direct control of image size using ``stc_plot_kwargs["size"]``
5+
- Improving :meth:`~mne.Report.add_evokeds` evoked topomap plotting by using :meth:`mne.Evoked.animate_topomap` with ``butterfly=True`` rather than re-plotting each topomap in a loop
6+
7+
Also improved :meth:`mne.Evoked.animate_topomap` by deduplicating code with :meth:`mne.Evoked.plot_topomap`. Changes by `Eric Larson`_.

examples/visualization/evoked_topomap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,4 @@
192192

193193
# sphinx_gallery_thumbnail_number = 9
194194
times = np.arange(0.05, 0.151, 0.01)
195-
fig, anim = evoked.animate_topomap(times=times, ch_type="mag", frame_rate=2, blit=False)
195+
fig, anim = evoked.animate_topomap(times=times, ch_type="mag", frame_rate=2)

mne/evoked.py

Lines changed: 96 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -791,21 +791,40 @@ def plot_joint(
791791
topomap_args=topomap_args,
792792
)
793793

794-
@fill_doc
794+
@verbose
795795
def animate_topomap(
796796
self,
797-
ch_type=None,
798-
times=None,
799-
frame_rate=None,
800797
*,
798+
times=None,
799+
average=None,
800+
ch_type=None,
801+
scalings=None,
802+
proj=False,
803+
sensors=True,
804+
show_names=False,
805+
mask=None,
806+
mask_params=None,
807+
contours=6,
808+
outlines="head",
809+
sphere=None,
810+
image_interp=_INTERPOLATION_DEFAULT,
811+
extrapolate=_EXTRAPOLATE_DEFAULT,
812+
border=_BORDER_DEFAULT,
813+
res=64,
814+
size=1.0,
801815
cmap=None,
816+
vlim=(None, None),
817+
cnorm=None,
818+
colorbar=True,
819+
cbar_fmt="%3.1f",
820+
units=None,
821+
axes=None,
822+
time_unit="s",
823+
time_format=None,
824+
frame_rate=None,
802825
butterfly=False,
803826
blit=True,
804827
show=True,
805-
time_unit="s",
806-
sphere=None,
807-
image_interp=_INTERPOLATION_DEFAULT,
808-
extrapolate=_EXTRAPOLATE_DEFAULT,
809828
vmin=None,
810829
vmax=None,
811830
verbose=None,
@@ -818,23 +837,44 @@ def animate_topomap(
818837
819838
Parameters
820839
----------
821-
ch_type : str | None
822-
Channel type to plot. Accepted data types: 'mag', 'grad', 'eeg',
823-
'hbo', 'hbr', 'fnirs_cw_amplitude',
824-
'fnirs_fd_ac_amplitude', 'fnirs_fd_phase', and 'fnirs_od'.
825-
If None, first available channel type from the above list is used.
826-
Defaults to None.
827840
times : array of float | None
828-
The time points to plot. If None, 10 evenly spaced samples are
829-
calculated over the evoked time series. Defaults to None.
841+
The time points to plot. If None (default), 10 evenly spaced samples are
842+
calculated over the evoked time series.
843+
%(average_plot_evoked_topomap)s
844+
%(ch_type_topomap)s
845+
%(scalings_topomap)s
846+
%(proj_plot)s
847+
%(sensors_topomap)s
848+
%(show_names_topomap)s
849+
%(mask_evoked_topomap)s
850+
%(mask_params_topomap)s
851+
%(contours_topomap)s
852+
%(outlines_topomap)s
853+
%(sphere_topomap_auto)s
854+
%(image_interp_topomap)s
855+
%(extrapolate_topomap)s
856+
%(border_topomap)s
857+
%(res_topomap)s
858+
%(size_topomap)s
859+
%(cmap_topomap)s
860+
%(vlim_plot_topomap_psd)s
861+
%(cnorm)s
862+
%(colorbar_topomap)s
863+
%(cbar_fmt_topomap)s
864+
%(units_topomap_evoked)s
865+
axes : list of matplotlib.axes.Axes | None
866+
The axes to use for plotting. Must have one axis for the topomap,
867+
then one for the colorbar (if ``colorbar=True``), then one for the
868+
butterfly axes (if ``butterfly=True``).
869+
time_unit : str
870+
The units for the time axis, can be "ms" or "s" (default).
871+
time_format : str | None
872+
String format for topomap values. Defaults (None) to "%%01d ms" if
873+
``time_unit='ms'``, "%%0.3f s" if ``time_unit='s'``, and
874+
"%%g" otherwise. Can be an empty string to omit the time label.
830875
frame_rate : int | None
831876
Frame rate for the animation in Hz. If None,
832877
frame rate = sfreq / 10. Defaults to None.
833-
cmap : matplotlib colormap | None
834-
Colormap to use. If None, 'Reds' is used for all positive data,
835-
otherwise defaults to 'RdBu_r'.
836-
837-
.. versionadded:: 1.12.0
838878
butterfly : bool
839879
Whether to plot the data as butterfly plot under the topomap.
840880
Defaults to False.
@@ -845,19 +885,10 @@ def animate_topomap(
845885
Defaults to True.
846886
show : bool
847887
Whether to show the animation. Defaults to True.
848-
time_unit : str
849-
The units for the time axis, can be "ms" (default in 0.16)
850-
or "s" (will become the default in 0.17).
851-
852-
.. versionadded:: 0.16
853-
%(sphere_topomap_auto)s
854-
%(image_interp_topomap)s
855-
%(extrapolate_topomap)s
856-
857-
.. versionadded:: 0.22
858-
%(vmin_vmax_topomap)s
859-
860-
.. versionadded:: 1.1.0
888+
vmin : float | None
889+
Deprecated, use ``vlim=(vmin, vmax)`` instead.
890+
vmax : float | None
891+
Deprecated, use ``vlim=(vmin, vmax)`` instead.
861892
%(verbose)s
862893
863894
Returns
@@ -869,24 +900,46 @@ def animate_topomap(
869900
870901
Notes
871902
-----
903+
.. versionchanged:: 1.13.0
904+
The ``vmin`` and ``vmax`` parameters were deprecated in favor of a single
905+
``vlim`` parameter, and parameters were added and reordered to follow
906+
:meth:`~mne.Evoked.plot_topomap`.
872907
.. versionadded:: 0.12.0
873908
"""
874909
return _topomap_animation(
875-
self,
876-
ch_type=ch_type,
910+
evoked=self,
877911
times=times,
878-
frame_rate=frame_rate,
879-
butterfly=butterfly,
880-
blit=blit,
881-
show=show,
882-
time_unit=time_unit,
912+
average=average,
913+
ch_type=ch_type,
914+
scalings=scalings,
915+
proj=proj,
916+
sensors=sensors,
917+
show_names=show_names,
918+
mask=mask,
919+
mask_params=mask_params,
920+
contours=contours,
921+
outlines=outlines,
883922
sphere=sphere,
884923
image_interp=image_interp,
885924
extrapolate=extrapolate,
925+
border=border,
926+
res=res,
927+
size=size,
928+
cmap=cmap,
929+
vlim=vlim,
930+
cnorm=cnorm,
931+
colorbar=colorbar,
932+
cbar_fmt=cbar_fmt,
933+
units=units,
934+
axes=axes,
935+
time_unit=time_unit,
936+
time_format=time_format,
937+
frame_rate=frame_rate,
938+
butterfly=butterfly,
939+
blit=blit,
886940
vmin=vmin,
887941
vmax=vmax,
888-
verbose=verbose,
889-
cmap=cmap,
942+
show=show,
890943
)
891944

892945
def as_type(self, ch_type="grad", mode="fast"):

0 commit comments

Comments
 (0)