Package mvpa :: Package misc :: Package plot :: Module erp
[hide private]
[frames] | no frames]

Module erp

source code

Basic ERP (here ERP = Event Related Plot ;-)) plotting

Can be used for plotting not only ERP but any event-locked data

Functions [hide private]
 
_offset(ax, x, y)
Provide offset in pixels
source code
 
_make_centeredaxis(ax, loc, offset=5, ai=0, mult=1.0, format='%4g', label=None, **props)
Plot an axis which is centered at loc (e.g. 0)
source code
 
plotERP(data, SR=500, onsets=None, pre=0.2, pre_onset=None, post=None, pre_mean=None, color='r', errcolor=None, errtype=None, ax=P, ymult=1.0, *args, **kwargs)
Plot single ERP on existing canvas
source code
 
plotERPs(erps, data=None, ax=None, pre=0.2, post=None, pre_onset=None, xlabel='time (s)', ylabel='$\mu V$', ylim=None, ymult=1.0, legend=None, xlformat='%4g', ylformat='%4g', loffset=10, alinewidth=2, **kwargs)
Plot multiple ERPs on a new figure.
source code

Imports: P, N, mpl, warning, BoxcarMapper, mlt


Function Details [hide private]

_offset(ax, x, y)

source code 

Provide offset in pixels

Idea borrowed from
http://www.scipy.org/Cookbook/Matplotlib/Transformations

but then heavily extended to be compatible with many reincarnations of matplotlib

Parameters:
  • x (int) - Offset in pixels for x
  • y (int) - Offset in pixels for y

_make_centeredaxis(ax, loc, offset=5, ai=0, mult=1.0, format='%4g', label=None, **props)

source code 

Plot an axis which is centered at loc (e.g. 0)

Idea borrowed from
http://www.mail-archive.com/matplotlib-users@lists.sourceforge.net /msg05669.html

It sustained heavy refactoring/extension

Parameters:

ax
Axes from the figure
loc
Value to center at
offset
Relative offset (in pixels) for the labels
ai : int
Axis index: 0 for x, 1 for y
mult
Multiplier for the axis labels. ERPs for instance need to be inverted, thus labels too manually here since there is no easy way in matplotlib to invert an axis
label : basestring or None
If not -- put a label outside of the axis
**props
Given to underlying plotting functions

plotERP(data, SR=500, onsets=None, pre=0.2, pre_onset=None, post=None, pre_mean=None, color='r', errcolor=None, errtype=None, ax=P, ymult=1.0, *args, **kwargs)

source code 
Plot single ERP on existing canvas
Returns:
array
Mean ERP timeseries.

Parameters:

data: 1D or 2D ndarray
The data array can either be 1D (samples over time) or 2D (trials x samples). In the first case a boxcar mapper is used to extract the respective trial timecourses given a list of trial onsets. In the latter case, each row of the data array is taken as the EEG signal timecourse of a particular trial.
onsets: list(int)
List of onsets (in samples not in seconds).
SR: int
Sampling rate (1/s) of the signal.
pre: float
Duration (in seconds) to be plotted prior to onset.
pre_onset : float or None
If data is already in epochs (2D) then pre_onset provides information on how many seconds pre-stimulus were used to generate them. If None, then pre_onset = pre
post: float
Duration (in seconds) to be plotted after the onset.
pre_mean: float
Duration (in seconds) at the beginning of the window which is used for deriving the mean of the signal. If None, pre_mean = pre
errtype: None | 'ste' | 'std' | 'ci95' | list of previous three
Type of error value to be computed per datapoint.
'ste': standard error of the mean 'std': standard deviation 'ci95': 95% confidence interval (1.96 * ste) None: no error margin is plotted (default)

Optionally, multiple error types can be specified in a list. In that case all of them will be plotted.

color: matplotlib color code
Color to be used for plotting the mean signal timecourse.
errcolor: matplotlib color code
Color to be used for plotting the error margin. If None, use main color but with weak alpha level
ax:
Target where to draw.
ymult: float
Multiplier for the values. E.g. if negative-up ERP plot is needed: provide ymult=-1.0
*args, **kwargs
Additional arguments to plot().

plotERPs(erps, data=None, ax=None, pre=0.2, post=None, pre_onset=None, xlabel='time (s)', ylabel='$\mu V$', ylim=None, ymult=1.0, legend=None, xlformat='%4g', ylformat='%4g', loffset=10, alinewidth=2, **kwargs)

source code 
Plot multiple ERPs on a new figure.

:Parameters:
  erps : list of tuples
    List of definitions of ERPs. Each tuple should consist of
    (label, color, onsets) or a dictionary which defines,
    label, color, onsets, data. Data provided in dictionary overrides
    'common' data provided in the next argument ``data``
  data
    Data for ERPs to be derived from 1D (samples)
  ax
    Where to draw (e.g. subplot instance). If None, new figure is
    created
  pre : float
    Duration (seconds) to be plotted prior to onset
  pre_onset : float or None
    If data is already in epochs (2D) then pre_onset provides information
    on how many seconds pre-stimulus were used to generate them. If None,
    then pre_onset = pre
  post : float or None
    Duration (seconds) to be plotted after the onset. If any data is
    provided with onsets, it can't be None. If None -- plots all time
    points after onsets
  ymult : float
    Multiplier for the values. E.g. if negative-up ERP plot is needed:
    provide ymult=-1.0
  xlformat : basestring
    Format of the x ticks
  ylformat : basestring
    Format of the y ticks
  legend : basestring or None
    If not None, legend will be plotted with position argument
    provided in this argument
  loffset : int
    Offset in voxels for axes and tick labels. Different
    matplotlib frontends might have different opinions, thus
    offset value might need to be tuned specifically per frontend
  alinewidth : int
    Axis and ticks line width
  **kwargs
    Additional arguments provided to plotERP()


:Examples:
    kwargs  = {'SR' : eeg.SR, 'pre_mean' : 0.2}
    fig = plotERPs((('60db', 'b', eeg.erp_onsets['60db']),
                     ('80db', 'r', eeg.erp_onsets['80db'])),
                    data[:, eeg.sensor_mapping['Cz']],
                    ax=fig.add_subplot(1,1,1,frame_on=False), pre=0.2,
                    post=0.6, **kwargs)

    or
    fig = plotERPs((('60db', 'b', eeg.erp_onsets['60db']),
                      {'color': 'r',
                       'onsets': eeg.erp_onsets['80db'],
                       'data' : data[:, eeg.sensor_mapping['Cz']]}
                     ),
                    data[:, eeg.sensor_mapping['Cz']],
                    ax=fig.add_subplot(1,1,1,frame_on=False), pre=0.2,
                    post=0.6, **kwargs)

:Returns: current fig handler