-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[BUG] Evoked.plot_topomap() and Evoked.plot_joint() handle the colormaps in a suboptimal manner #13050
Description
Description of the problem
This might be somewhat controversial as a bug report and is partially a matter of taste.
There is a combination of two issues, which leads to suboptimal results when producing plots with the default parameters using Evoked.plot_topomap() and Evoked.plot_joint().
Essentially, an unpredictable amount of whitespace is left above and below the colored portion of the colorbar when using Evoked.plot_topomap(). This is seen in all MNE examples using topomaps, for example, Plotting topographic maps of evoked data. The reason is that the colorbar ticks follow the contours (as they should), while the colored part is dependent on vlim (by default set symmetrically such that vmax = np.abs(data).max()). The default behavior is to set six contours using matplotlib.ticker.MaxNLocator, which adds locations beyond the minimum and maximum of the data to obtain "nice" values for the ticks. I wonder if it would be better to scale then also the colormap limits to match the smallest and largest ticks?
This issue can, of course, be circumvented by explicitly setting both vlim and contours.
Moreover, when using Evoked.plot_joint() without specifying vlim, the vlim for the topomaps are selected based on the data at the selected time points (inside plot_evoked_topomap). At the same time, the contours, and correspondingly, the colorbar ticks, are selected based on the ylim of the time series plot. In my opinion, it would be better to do the following:
- If
vlimare specified for the topomap, use thosevlimalso to set the contours (unlesscontoursare set explicitly). The current behavior is to use theylimfrom the time series plot to determine the contours unlesscontoursis set explicitly. - If
vlimare not specified for the topomap, set the contours similar to what is now done inEvoked.plot_topomap(), usingvmax = np.abs(data).max()at the topomap timepoints.
Steps to reproduce
"""
Minimal working example based on the tutorial "Plotting topographic maps of evoked data".
"""
# %%
import numpy as np
from mne import read_evokeds
from mne.datasets import sample
path = sample.data_path()
fname = path / "MEG" / "sample" / "sample_audvis-ave.fif"
# load evoked corresponding to a specific condition
# from the fif file and subtract baseline
condition = "Left Auditory"
evoked = read_evokeds(fname, condition=condition, baseline=(None, 0))
# %%
times = np.arange(0.05, 0.151, 0.02)
evoked.plot_topomap(times, ch_type="mag")
# %%
evoked.plot_joint(picks='mag')Link to data
No response
Expected results
Actual results
Instead this happens:
Here's an example of what happens when suboptimal time points are picked:

Additional information
I don't know if this is a feature or a bug, but here's to open discussion. I can make a PR if this is something that you want to change.


