spykeutils.plot package
This package contains various plotting functions for neo objects.
The plots are created using guiqwt - if it is not installed,
this package can not be used.
-
raster(trains, time_unit=UnitTime('millisecond', 0.001 * s, 'ms'), show_lines=True, events=None, epochs=None)[source]
Create a new plotting window with a rasterplot of spiketrains.
Parameters: |
- trains (dict) – Dictionary of spike trains indexed by a
Neo object (Unit or Segment).
- time_unit (Quantity) – Unit of X-Axis.
- show_lines (bool) – Determines if a horizontal line will be shown
for each spike train.
- events (sequence) – A sequence of neo Event objects that will
be marked on the plot.
|
-
cross_correlogram(trains, bin_size, max_lag=array(500.0) * ms, border_correction=True, per_second=True, square=False, time_unit=UnitTime('millisecond', 0.001 * s, 'ms'), progress=None)[source]
Create (cross-)correlograms from a dictionary of spike train
lists for different units.
Parameters: |
- trains (dict) – Dictionary of neo.core.SpikeTrain lists.
- bin_size (Quantity scalar) – Bin size (time).
- max_lag (Quantity scalar) – Maximum time lag for which spikes are considered
(end time of calculated correlogram).
- border_correction (bool) – Apply correction for less data at higher
timelags.
- per_second (bool) – If True, the y-axis is count per second,
otherwise it is count per spike train.
- square (bool) – If True, the plot will include all
cross-correlograms, even if they are just mirrored versions of each
other. The autocorrelograms are displayed as the diagonal of a
square plot matrix. If False, mirrored plots are omitted.
- time_unit (Quantity) – Unit of X-Axis.
- progress (spykeutils.progress_indicator.ProgressIndicator) – Set this parameter to report progress.
|
-
isi(trains, bin_size, cut_off, bar_plot=False, time_unit=UnitTime('millisecond', 0.001 * s, 'ms'))[source]
Create a plot dialog with an interspike interval histogram.
Parameters: |
- trains (dict) – Dictionary with lists of spike trains indexed by
units for which to display ISI histograms
- bin_size (Quantity scalar) – Bin size (time)
- cut_off – End of histogram (time)
- bar_plot (bool) – If True, create a bar ISI histogram for each
index in trains. Else, create a line ISI histogram.
- time_unit (Quantity) – Unit of X-Axis.
|
-
psth(trains, events=None, start=array(0.0) * ms, stop=None, bin_size=array(100.0) * ms, rate_correction=True, bar_plot=False, time_unit=UnitTime('millisecond', 0.001 * s, 'ms'), progress=None)[source]
Create a peri stimulus time histogram.
The peri stimulus time histogram gives an estimate of the instantaneous
rate.
Parameters: |
- trains (dict) – A dictionary of neo.core.SpikeTrain lists.
- events (dict) – A dictionary of Event objects, indexed by segment.
The events will be at time 0 on the plot. If None, spike trains
are used unmodified.
- start (Quantity scalar) – The desired time for the start of the first bin. It
will be recalculated if there are spike trains which start later
than this time. This parameter can be negative (which could be
useful when aligning on events).
- stop (Quantity scalar) – The desired time for the end of the last bin. It will
be recalculated if there are spike trains which end earlier
than this time.
- bin_size (Quantity scalar) – The bin size for the histogram.
- rate_correction (bool) – Determines if a rates (True) or
counts (False) are shown.
- bar_plot (bool) – Determines if a bar plot (True) or a line
plot (False) will be created. In case of a bar plot, one plot
for each index in trains will be created.
- time_unit (Quantity) – Unit of X-Axis.
- progress (spykeutils.progress_indicator.ProgressIndicator) – Set this parameter to report progress.
|
-
sde(trains, events=None, start=array(0.0) * ms, stop=None, kernel_size=array(100.0) * ms, optimize_steps=0, minimum_kernel=array(10.0) * ms, maximum_kernel=array(500.0) * ms, kernel=None, time_unit=UnitTime('millisecond', 0.001 * s, 'ms'), progress=None)[source]
Create a spike density estimation plot.
The spike density estimations give an estimate of the instantaneous
rate. Optionally finds optimal kernel size for given data.
Parameters: |
- trains (dict) – A dictionary of neo.core.SpikeTrain lists.
- events (dict) – A dictionary (with the same indices as trains)
of Event objects or lists of Event objects. In case of lists,
the first event in the list will be used for alignment. The events
will be at time 0 on the plot. If None, spike trains are used
unmodified.
- start (Quantity scalar) – The desired time for the start of the first bin. It
will be recalculated if there are spike trains which start later
than this time. This parameter can be negative (which could be
useful when aligning on events).
- stop (Quantity scalar) – The desired time for the end of the last bin. It will
be recalculated if there are spike trains which end earlier
than this time.
- kernel_size (Quantity scalar) – A uniform kernel size for all spike trains.
Only used if optimization of kernel sizes is not used (i.e.
optimize_steps is 0).
- optimize_steps (int) – The number of different kernel sizes tried
between minimum_kernel and maximum_kernel.
If 0, kernel_size will be used.
- minimum_kernel (Quantity scalar) – The minimum kernel size to try in optimization.
- maximum_kernel (Quantity scalar) – The maximum kernel size to try in optimization.
- kernel (func or spykeutils.signal_processing.Kernel) – The kernel function or instance to use, should accept
two parameters: A ndarray of distances and a kernel size.
The total area under the kernel function should be 1.
Automatic optimization assumes a Gaussian kernel and will
likely not produce optimal results for different kernels.
Default: Gaussian kernel
- time_unit (Quantity) – Unit of X-Axis.
- progress (spykeutils.progress_indicator.ProgressIndicator) – Set this parameter to report progress.
|
-
signals(signals, events=None, epochs=None, spike_trains=None, spikes=None, show_waveforms=True, use_subplots=True, subplot_names=True, time_unit=UnitTime('second', 's'), y_unit=None, progress=None)[source]
Create a plot from a list of analog signals.
Parameters: |
- signals (list) – The list of neo.core.AnalogSignal objects
to plot.
- events (sequence) – A list of Event objects to be included in the
plot.
- epochs (sequence) – A list of Epoch objects to be included in the
plot.
- spike_trains (list) – A list of neo.core.SpikeTrain objects
to be included in the plot. The unit property (if it exists) is
used for color and legend entries.
- spikes (list) – A list neo.core.Spike objects to be included
in the plot. The unit property (if it exists) is used for color
and legend entries.
- show_waveforms (bool) – Determines if spikes from
neo.core.Spike and neo.core.SpikeTrain objects are
shown as waveforms (if available) or vertical lines.
- use_subplots (bool) – Determines if a separate subplot for is created
each signal.
- subplot_names (bool) – Only valid if use_subplots is True.
Determines if signal (or channel) names are shown for subplots.
- time_unit (Quantity) – The unit of the x axis.
- progress (spykeutils.progress_indicator.ProgressIndicator) – Set this parameter to report progress.
|
-
spike_amplitude_histogram(trains, num_bins, uniform_y_scale=True, x_unit=UnitQuantity('microvolt', 1e-06 * V, 'uV'), progress=None)[source]
Create a spike amplitude histogram.
This plot is useful to assess the drift in spike amplitude over a longer
recording. It shows histograms (one for each trains entry, e.g. segment)
of maximum and minimum spike amplitudes.
Parameters: |
- trains (list) – A list of lists of neo.core.SpikeTrain
objects. Each entry of the outer list will be one point on the
x-axis (they could correspond to segments), all amplitude occurences
of spikes contained in the inner list will be added up.
- num_bins (int) – Number of bins for the histograms.
- uniform_y_scale (bool) – If True, the histogram for each channel
will use the same bins. Otherwise, the minimum bin range is computed
separately for each channel.
- x_unit (Quantity) – Unit of Y-Axis.
- progress (spykeutils.progress_indicator.ProgressIndicator) – Set this parameter to report progress.
|
Returns: |
|
-
spikes(spikes, axes_style, strong=None, anti_alias=False, fade=1.0, subplot_layout=0, time_unit=UnitTime('millisecond', 0.001 * s, 'ms'), progress=None)[source]
Create a plot dialog with spike waveforms. Assumes that all spikes
have waveforms with the same number of channels.
dialog Module
Contains a helper class for creating windows containing guiqwt plots.
-
class PlotDialog(wintitle='Plot window', major_grid=True, minor_grid=False, toolbar=True, parent=None, panels=None, min_plot_width=100, min_plot_height=75)[source]
Bases: PyQt4.QtGui.QDialog, guiqwt.plot.PlotManager
Implements a dialog to which an arbitrary number of plots can be
added.
This class implements a QDialog with a number of plots on it. The
axes of the plots can be arbitrarily synchronized and option checkboxes
can be added which provide callbacks when the checkbox state changes.
Parameters: |
- wintitle (str) – Title of the window.
- major_grid (bool) – Show major grid in plots.
- minor_grid (bool) – Show minor grid in plots.
- toolbar (bool) – Show toolbar.
- parent – Parent window.
- panels – A list of guiqwt panels to be added to the window.
- min_plot_width (int) – Default minimum width for plots.
- min_plot_height (int) – Default minimum height for plots.
|
-
add_color_legend(legend, show_option=None)[source]
Create a legend on the right of the plots with colors and names.
Parameters: |
- legend (sequence) – List of (color, text) tuples, where color
is a Qt color name (e.g. ‘#ff0000’) and text is the
corresponding text to display in the legend.
- show_option (bool) – Determines whether a toggle for the legend
will be shown (if the parameter is not None) and if the legend
is visible initially (True/False).
|
-
add_custom_curve_tools(antialiasing=True, activate_zoom=True, signal_stats=False)[source]
Adds typically needed curve tools to the window.
Parameters: |
- antialiasing (bool) – Determines if the antialiasing tool is
added.
- activate_zoom (bool) – Determines if the zoom tool is activated
initially (otherwise, the selection tool will be activated).
- signal_stats (bool) – Determines if the signal stats tool is
available.
|
-
add_custom_image_tools(activate_zoom=True)[source]
Adds typically needed image tools to the window.
-
add_custom_label(legend_string)[source]
Add a label on the right of the plots
Parameters: | legend_string (str) – An arbitrary string (which can contain
newlines) to display on the right of the plots |
-
add_legend_option(legends, active)[source]
Create a user option to show or hide a list of legend objects.
Parameters: |
- legends (sequence) – The legend objects affected by the option.
- active (bool) – Determines whether the legends will be visible
initially.
|
-
add_option(name, change_callback, active=False)[source]
Add an option (using a checkbox) to the window.
Parameters: |
- name (str) – The name of the option.
- change_callback (func) – A function accepting the new state as
a parameter. The function will be called whenever the state
of the option changes.
- active (bool) – Determines if the option is activated initially.
|
-
add_plot_widget(plot_widget, plot_id, row=-1, column=0, min_plot_width=None, min_plot_height=None)[source]
Adds a guiqwt plot to the window.
Parameters: |
- plot_widget (guiqwt plot widget) – The plot to add.
- plot_id (int) – The id of the new plot.
- row (int) – The row of the new plot. If this is -1, the new plot
will be added in a new row (if column is 0) or
in the last row.
- column (int) – The column of the new plot.
- min_plot_width (int) – The minimum width of this plot. If
None, the default minimum width for this dialog
is used.
- max_plot_height (int) – The minimum height of this plot. If
None, the default minimum height for this dialog
is used.
|
-
add_unit_color(color, name='Unit color:')[source]
Create a small legend on top of the window with only one entry.
Parameters: |
- color (str) – A Qt color name (e.g. ‘#ff0000’)
- name (str) – The name of the legend item. It will be displayed
on the left of the color.
|
-
add_x_synchronization_option(active, ids=None)[source]
Offer an option for X axes synchronization. This method should
be called after show(), so that a proper initial synchronization
can be performed.
Parameters: |
- active (bool) – Determines whether the axes are synchronized
initially.
- ids (sequence) – List of plot ids to synchronize.
|
-
add_y_synchronization_option(active, ids=None)[source]
Offer an option for Y axes synchronization. This method should
be called after show(), so that a proper initial synchronization
can be performed.
Parameters: |
- active (bool) – Determines whether the axes are synchronized
initially
- ids (sequence) – List of plot ids to synchronize.
|
-
replace_colors(replace_list)[source]
Replace colors of items in all plots.
This can be useful when changing the background color to black
and black items should be drawn in white:
replace_colors([('#000000', '#ffffff']))
Parameters: | replace_list (list) – A list of tuples of Qt color names. The
first color in each tuple is replaced by the second color. |
-
set_background_color(color)[source]
Set the background color for all plots.
Parameters: | color (str) – A Qt color name (e.g. ‘#ff0000’) |
-
set_plot_title(plot, title)[source]
- Set the title of a guiqwt plot and use the same font as for the
- rest of the window.
Parameters: |
- plot – The plot for which the title is set.
- title (str) – The new title of the plot.
|
helper Module
This module contains some utility functions that are usefult in plot creation.
-
class ProgressIndicatorDialog(parent, title='Processing...')[source]
This class implements
spykeutils.progress_indicator.ProgressIndicator as a
QProgressDialog. It can be used to indicate progress in a graphical
user interface. Qt needs to be initialized in order to use it.
-
add_epochs(plot, epochs, units=None)[source]
Add Epoch markers to a guiqwt plot.
Parameters: |
- plot (guiqwt.baseplot.BasePlot) – The plot object.
- epochs (sequence) – The epochs (neo neo.Epoch objects).
- units – The x-scale of the plot. If this is None,
the time unit of the events will be use.
|
-
add_events(plot, events, units=None)[source]
Add Event markers to a guiqwt plot.
Parameters: |
- plot (guiqwt.baseplot.BasePlot) – The plot object.
- events (sequence) – The events (neo neo.Event objects).
- units (Quantity) – The x-scale of the plot. If this is None,
the time unit of the events will be use.
|
-
add_spikes(plot, train, color='k', spike_width=1, spike_height=20000, y_offset=0, name='', units=None)[source]
Add all spikes from a spike train to a guiqwt plot as vertical lines.
Parameters: |
- plot (guiqwt.baseplot.BasePlot) – The plot object.
- train (neo.core.SpikeTrain) – A spike train with the spike times to show.
- color (str) – The color for the spikes.
- spike_width (int) – The width of the shown spikes in pixels.
- spike_height (int) – The height of the shown spikes in pixels.
- y_offset (float) – An offset for the drawing position on the y-axis.
- name (str) – The name of the spike train.
- units (Quantity) – The x-scale of the plot. If this is None,
the time unit of the events will be use.
|
Returns: | The plot item added for the spike train
|
-
get_color(entity_id)[source]
Return a color for an int.
-
get_object_color(unit)[source]
Return a color for a Neo object, based on the ‘unique_id’
annotation. If the annotation is not present, return a color based
on the hash of the object.
-
make_window_legend(win, objects, show_option=None)[source]
Create a legend in a PlotDialog for a given sequence of neo objects.
Parameters: |
- win (spykeutils.plot.dialogs.PlotDialog) – The window where the legend will be added.
- objects (sequence) – A list of neo objects which will be included in
the legend.
- show_option (bool) – Determines whether a toggle for the legend
will be shown (if the parameter is not None) and if the legend
is visible initially (True/False).
|
-
needs_qt(func)[source]
Decorator for functions making sure that an initialized PyQt exists.
-
set_color_scheme(colors)[source]
Set the color scheme used in plots.
Parameters: | colors (sequence) – A list of strings with HTML-style color codes
(e.g. '#ffffff' for white). If this is None or empty,
the default color scheme will be set. |