mne.viz.plot_compare_evokeds#
- mne.viz.plot_compare_evokeds(evokeds, picks=None, colors=None, linestyles=None, styles=None, cmap=None, vlines='auto', ci=True, truncate_yaxis='auto', truncate_xaxis=True, ylim=None, invert_y=False, show_sensors=None, legend=True, split_legend=None, axes=None, title=None, show=True, combine=None, sphere=None)[source]#
Plot evoked time courses for one or more conditions and/or channels.
- Parameters
- evokedsinstance of
mne.Evoked
|list
|dict
If a single Evoked instance, it is plotted as a time series. If a list of Evokeds, the contents are plotted with their
.comment
attributes used as condition labels. If no comment is set, the index of the respective Evoked the list will be used instead, starting with1
for the first Evoked. If a dict whose values are Evoked objects, the contents are plotted as single time series each and the keys are used as labels. If a [dict/list] of lists, the unweighted mean is plotted as a time series and the parametric confidence interval is plotted as a shaded area. All instances must have the same shape - channel numbers, time points etc. If dict, keys must be of type str.- picks
str
|list
|slice
|None
Channels to include. Slices and lists of integers will be interpreted as channel indices. In lists, channel type strings (e.g.,
['meg', 'eeg']
) will pick channels of those types, channel name strings (e.g.,['MEG0111', 'MEG2623']
will pick the given channels. Can also be the string values “all” to pick all channels, or “data” to pick data channels. None (default) will pick all data channels. Note that channels ininfo['bads']
will be included if their names or indices are explicitly provided.If picks is None or a (collection of) data channel types, the global field power will be plotted for all data channels. Otherwise, picks will be averaged.
If multiple channel types are selected, one figure will be returned for each channel type.
If the selected channels are gradiometers, the signal from corresponding (gradiometer) pairs will be combined.
- colors
list
|dict
|None
Colors to use when plotting the ERP/F lines and confidence bands. If
cmap
is notNone
,colors
must be alist
ordict
ofints
orfloats
indicating steps or percentiles (respectively) along the colormap. Ifcmap
isNone
, list elements or dict values ofcolors
must beints
or valid matplotlib colors; lists are cycled through sequentially, while dicts must have keys matching the keys or conditions of anevokeds
dict (see Notes for details). IfNone
, the current matplotlib color cycle is used. Defaults toNone
.- linestyles
list
|dict
|None
Styles to use when plotting the ERP/F lines. If a
list
ordict
, elements must be valid matplotlib linestyles. Lists are cycled through sequentially; dictionaries must have keys matching the keys or conditions of anevokeds
dict (see Notes for details). IfNone
, all lines will be solid. Defaults toNone
.- styles
dict
|None
Dictionary of styles to use when plotting ERP/F lines. Keys must match keys or conditions of
evokeds
, and values must be adict
of legal inputs tomatplotlib.pyplot.plot()
. Those values will be passed as parameters to the line plot call of the corresponding condition, overriding defaults (e.g.,styles={"Aud/L": {"linewidth": 3}}
will set the linewidth for “Aud/L” to 3). As withcolors
andlinestyles
, keys matching conditions in/
-separatedevokeds
keys are supported (see Notes for details).- cmap
None
|str
|tuple
| instance ofmatplotlib.colors.Colormap
Colormap from which to draw color values when plotting the ERP/F lines and confidence bands. If not
None
, ints or floats in thecolors
parameter are mapped to steps or percentiles (respectively) along the colormap. Ifcmap
is astr
, it will be passed tomatplotlib.cm.get_cmap()
; ifcmap
is a tuple, its first element will be used as a string to label the colorbar, and its second element will be passed tomatplotlib.cm.get_cmap()
(unless it is already an instance ofColormap
).Changed in version 0.19: Support for passing
Colormap
instances.- vlines“auto” |
list
offloat
A list in seconds at which to plot dashed vertical lines. If “auto” and the supplied data includes 0, it is set to [0.] and a vertical bar is plotted at time 0. If an empty list is passed, no vertical lines are plotted.
- ci
float
| bool |callable()
|None
Confidence band around each ERP/F time series. If
False
orNone
no confidence band is drawn. Iffloat
,ci
must be between 0 and 1, and will set the threshold for a bootstrap (single plot)/parametric (whenaxes=='topo'
) estimation of the confidence band;True
is equivalent to setting a threshold of 0.95 (i.e., the 95% confidence band is drawn). If a callable, it must take a single array (n_observations × n_times) as input and return upper and lower confidence margins (2 × n_times). Defaults toTrue
.- truncate_yaxisbool | ‘auto’
Whether to shorten the y-axis spine. If ‘auto’, the spine is truncated at the minimum and maximum ticks. If
True
, it is truncated at the multiple of 0.25 nearest to half the maximum absolute value of the data. Iftruncate_xaxis=False
, only the far bound of the y-axis will be truncated. Defaults to ‘auto’.- truncate_xaxisbool
Whether to shorten the x-axis spine. If
True
, the spine is truncated at the minimum and maximum ticks. Iftruncate_yaxis=False
, only the far bound of the x-axis will be truncated. Defaults toTrue
.- ylim
dict
|None
Y-axis limits for plots (after scaling has been applied).
dict
keys should match channel types; valid keys are eeg, mag, grad, misc (example:ylim=dict(eeg=[-20, 20])
). IfNone
, the y-axis limits will be set automatically by matplotlib. Defaults toNone
.- invert_ybool
Whether to plot negative values upward (as is sometimes done for ERPs out of tradition). Defaults to
False
.- show_sensorsbool |
int
|str
|None
Whether to display an inset showing sensor locations on a head outline. If
int
orstr
, indicates position of the inset (seempl_toolkits.axes_grid1.inset_locator.inset_axes()
). IfNone
, treated asTrue
if there is only one channel inpicks
. IfTrue
, location is upper or lower right corner, depending on data values. Defaults toNone
.- legendbool |
int
|str
Whether to show a legend for the colors/linestyles of the conditions plotted. If
int
orstr
, indicates position of the legend (seempl_toolkits.axes_grid1.inset_locator.inset_axes()
). IfTrue
, equivalent to'upper left'
. Defaults toTrue
.- split_legendbool |
None
Whether to separate color and linestyle in the legend. If
None
, a separate linestyle legend will still be shown ifcmap
is specified. Defaults toNone
.- axes
None
|Axes
instance |list
ofAxes
| ‘topo’ Axes
object to plot into. If plotting multiple channel types (or multiple channels whencombine=None
),axes
should be a list of appropriate length containingAxes
objects. If'topo'
, a newFigure
is created with one axis for each channel, in a topographical layout. IfNone
, a newFigure
is created for each channel type. Defaults toNone
.- title
str
|None
Title printed above the plot. If
None
, a title will be automatically generated based on channel name(s) or type(s) and the value of thecombine
parameter. Defaults toNone
.- showbool
Whether to show the figure. Defaults to
True
.- combine
None
|str
|callable()
How to combine information across channels. If a
str
, must be one of ‘mean’, ‘median’, ‘std’ (standard deviation) or ‘gfp’ (global field power). If callable, the callable must accept one positional input (data of shape(n_evokeds, n_channels, n_times)
) and return anarray
of shape(n_epochs, n_times)
. For example:combine = lambda data: np.median(data, axis=1)
If
combine
isNone
, channels are combined by computing GFP, unlesspicks
is a single channel (not channel type) oraxes='topo'
, in which cases no combining is performed. Defaults toNone
.- sphere
float
| array-like |str
|None
The sphere parameters to use for the cartoon head. Can be array-like of shape (4,) to give the X/Y/Z origin and radius in meters, or a single float to give the radius (origin assumed 0, 0, 0). Can also be a spherical ConductorModel, which will use the origin and radius. Can be “auto” to use a digitization-based fit. Can also be None (default) to use ‘auto’ when enough extra digitization points are available, and 0.095 otherwise. Currently the head radius does not affect plotting.
New in version 0.20.
- evokedsinstance of
- Returns
Notes
If the parameters
styles
,colors
, orlinestyles
are passed asdicts
, thenevokeds
must also be adict
, and the keys of the plot-style parameters must either match the keys ofevokeds
, or match a/
-separated partial key (“condition”) ofevokeds
. For example, if evokeds has keys “Aud/L”, “Aud/R”, “Vis/L”, and “Vis/R”, thenlinestyles=dict(L='--', R='-')
will plot both Aud/L and Vis/L conditions with dashed lines and both Aud/R and Vis/R conditions with solid lines. Similarly,colors=dict(Aud='r', Vis='b')
will plot Aud/L and Aud/R conditions red and Vis/L and Vis/R conditions blue.Color specification depends on whether a colormap has been provided in the
cmap
parameter. The following table summarizes how thecolors
parameter is interpreted:cmap
colors
result
None
None
matplotlib default color cycle; unique color for each condition
list or dict of integers
matplotlib default color cycle; lowest integer mapped to first cycle color; conditions with same integer get same color; unspecified conditions are “gray”
list or dict of floats
ValueError
list or dict of hexadecimal color strings
the specified hex colors; unspecified conditions are “gray”
string or instance of matplotlib Colormap
None
equally spaced colors on the colormap; unique color for each condition
list or dict of integers
equally spaced colors on the colormap; lowest integer mapped to first cycle color; conditions with same integer get same color
list or dict of floats
floats mapped to corresponding colormap values
list or dict of hexadecimal color strings
TypeError
Examples using mne.viz.plot_compare_evokeds
#
Overview of MEG/EEG analysis with MNE-Python
Preprocessing functional near-infrared spectroscopy (fNIRS) data
Auto-generating Epochs metadata
EEG processing and Event Related Potentials (ERPs)
Spatiotemporal permutation F-test on full sensor data
Make figures more publication ready
Analysing continuous features with binning and regression in sensor space
Single trial linear regression analysis with the LIMO dataset