Plot spike data in a raster plot.
Plot spike times as a raster plot where the horizontal axis is time and the rows of the vertical axis are spike trains of individual neurons. This sets and holds many variables for plotting such that the user can simply set the parameters once and then redraw the spikes or scale and zoom to navigate spike data.
This simple example generates some random “spikes” and displays them.
import numpy from neuronpy.graphics import spikeplot spikes =  num_cells = 10 num_spikes_per_cell = 20 frequency = 20 # Make the spike data. Use a simple Poisson-like spike generator # (just for illustrative purposes here. Better spike generators should # be used in simulations). for i in range(num_cells): isi=numpy.random.poisson(frequency, num_spikes_per_cell) spikes.append(numpy.cumsum(isi)) # spikes is now a list of lists where each cell has a list of spike # times. Now, let's plot these spikes. sp = spikeplot.SpikePlot(savefig=True) sp.plot_spikes(spikes)
THOMAS MCTAVISH (2010-03-01): initial version, 0.1
spikesums to coexist better.
Manager for the spike raster axes as well as the axes manager for SpikeTimeHistogram, and SpikeSum subplots. Additionally, the line formatting parameters in SpikeParams funnel through this object. In fact, it may be rare to access those classes directly and instead use the methods in this class
Plots are drawn iteratively in that the user specifies the drawing parameters for a set of spikes before telling the SpikePlot object to plot any spikes. Therefore, when plotting multiple sets of spikes in the same plot, the paradigm is:
sp = SpikePlot() sp.plot_spikes(some_spikes) sp.set_<some_line_format_method>() sp.set_<some_other_formatting_options>() sp.plot_spikes(some_other_spikes)
Indeed, the method to be most familiar with is plot_spikes().
If the spike data is not too large to fit into RAM and you want to navigate it, it is generally a good idea to specify the complete data to plot and then simply modify the view of the axes to zoom or translate the plot. This is detailed in update_xlim().
Parameters can be set during instanciation of a SpikePlot object by passing in various <parameter>=<value> pairs or through accessor methods, get_<parameter>() and set_<parameter>(). As <parameter>=<value> pairs, they use the kwargs (short for keyword arguments) parameter on instanciation. Below is a summary of keyword parameters, which are more detailed in the corresponding set_<parameter>() method. Some lesser-used parameters have accessor methods, but are not available as keyword parameters.
Summary of SpikePlot keyword parameters:
|fig||The Figure handle.||None|
|fig_name||Name of figure, if saved as a file.||'spikeplot.png'|
|figsize||Size of the figure, in inches.||(8, 6)|
|marker||Tick marks style.||'|'|
|markercolor||Line and marker color.||'black'|
|markeredgewidth||Line and edge width of tick marks.||0.75|
|markerscale||Tick mark row height.||1.0|
|savefig||Flag to save a figure to a file when drawing.||False|
|sth_ratio||SpikeTimeHistogram axes height.||0|
|sum_ratio||SpikeSum Histogram axes width.||0|
Returns the amount of padding between the raster axes and the spike time histogram and/or spike sum axes if they are drawn.
Returns the amount of padding in terms of the data width to draw a full-screen image. The data width is the last spike in the data minus the first spike in the data. The pad ensures that the first and last spike will appear in the figure and not be blocked by the vertical axis.
Returns a handle to the Figure.
Returns the name of the file that will be written when plotted with the savefig variable set to True.
Returns the size of the figure in inches.
Returns the linestyle of the raster plot.
Returns the line width of the raster plot if the linestyle is not ‘none’.
Returns the marker type for raster tick marks.
Returns the marker and line color.
Returns the size of the tick mark edge. In the case of a vertical bar, this is the linewidth of that bar.
Returns the relative size of the marker in the raster plot.
Returns a handle to the raster axes.
Returns the flag of whether a file is saved upon plotting.
Returns the instance of the SpikeTimeHistogram object.
Returns the instance of the SpikeSum object.
Plot the spikes. This sets or appends the spike data to be drawn. If a single snapshot is needed, simply pass in the desired spikes to plot. If, however, the plot is to be interactive, it is best to send the full range of spikes and then zoom and translate by modifying the axes via the update_xlim() method.
Set the amount of padding between the spike axes and the spike time histogram and cumulative spike plot if they are shown.
|Parameters:||pad (float; default 0.01) – amount to pad. This value is in figure coordinates and needs to be between 0 and 1, and probably very close to 0. A value of 0 means that the axes touch each other.|
Set the amount of padding in terms of the data width to draw a full-screen image. The data width is the last spike in the data minus the first spike in the data. The pad ensures that the first and last spike will appear in the figure and not be blocked by the vertical axis.
|Parameters:||pad (float; default 0.025) – amount to pad. The default value of 0.025 means that the maximum x-axis dimensions will be (first_spike - 0.025*data_width, last_spike + 0.025*data_width).|
Set the figure handle.
|Parameters:||fig – the figure handle. If this is not None, then this also instantiates the ax axes by either creating one if it does not already exist in the figure, or by assigning the first axes object. If None, then the figure handle and the axes handle are both set to None.|
Sets the name of the output figure.
|Parameters:||fig_name (str; default “spikeplot.png”) – the output file name.|
The extension should be included with the name and should be a valid graphics format supported by the backend drawing system. This is not checked for, but most graphics formats include png, pdf, ps, eps and svg.
Set the figure size in inches.
|Parameters:||figsize (tuple; default None) – a tuple specified as (width, height). If None, then it will use the Matplotlib default for a figure size when creating a new figure.|
Sets the horizontal line style. Valid styles are defined by Matplotlib.lines.Line2D linestyle.
Sets the width of the horizontal line for each cell, if the linestyle is not ‘None’.
|Parameters:||linewidth (float; default 0.75) – the width of the line.|
Sets the tick mark symbol. Valid markers are defined by Matplotlib.lines.Line2D markers.
Set the marker color.
|Parameters:||color – Any Matplotlib color.|
Any subsequent drawing will keep this color, so call get_markercolor() if you want to restore drawing.
Sets the edge thickness of the tick mark.
|Parameters:||markeredgewidth (float; default 0.75) – the thickness of the marker.|
Sets the scale of the tick marks between rows.
|Parameters:||markerscale – the relative marker size between rows. A value of 1 means that the tick mark, if the marker is |, will make it so that each row just touches. Smaller values will make the marker size smaller and larger values will cause the markers to bleed across rows.|
Sets (or resets) the raster axes to the axes handle passed in. This may be necessary when resizing the image or axes so that the markers can be resized to scale with the image.
Set the flag to save a figure after drawing. The name of the file is defined by the fig_name variable.
|Parameters:||savefig – is a boolean to specify whether to save the plotted figure to a file. By default this is False. When set to True, the file specified by the fig_name member variable is written.|
Since the interactive reference running on the NEURON SAGE server draws graphics by importing images into the web page. Many examples set savefig to True during instanciation for proper functionality with that guide.
Set the ratio of the spike time histogram axes to the figure.
|Parameters:||sth_ratio (float; default is zero.) – is the vertical amount between [0,1] in figure space to draw a spike time histogram. A value of zero means that the spike time histogram axes is not drawn. A value of 0.5 means that the figure will split vertically in half the spike raster and the histogram. A value of 1.0 means that the spike raster is not drawn but the histogram takes up the whole space.|
Set the ratio of the spike sum histogram axes to the figure.
|Parameters:||sum_ratio (float; default is zero.) – is the horizontal amount between [0,1] in figure space to draw a spike time histogram. A value of zero means that the spike time histogram axes is not drawn. A value of 0.5 means that the figure will split vertically in half the spike raster and the histogram. A value of 1.0 means that the spike raster is not drawn but the histogram takes up the whole space.|
Update the xlim of the raster axes and propagate this info to the other axes if they are visible, redrawing and re-writing a figure if necessary.
|Parameters:||xlim – is a tuple of length 2 specifying the new axes bounds.|