Plotting¶
NeuroVis¶
-
class
spykes.plot.neurovis.
NeuroVis
(spiketimes, name='neuron')[source]¶ This class is used to visualize firing activity of single neurons.
This class implements several conveniences for visualizing firing activity of single neurons.
Parameters: - spiketimes (Numpy array) – Array of spike times.
- name (str) – The name of the visualization.
-
get_psth
(event=None, df=None, conditions=None, cond_id=None, window=[-100, 500], binsize=10, plot=True, event_name=None, conditions_names=None, ylim=None, colors=['#F5A21E', '#134B64', '#EF3E34', '#02A68E', '#FF07CD'])[source]¶ Compute the PSTH and plot it.
Parameters: - event (str) – Column/key name of DataFrame/dictionary
data
which contains event times in milliseconds (e.g. stimulus/trial/fixation onset, etc.) - conditions (str) – Column/key name of DataFrame/dictionary
data
which contains the conditions by which the trials must be grouped. - cond_id (list) – Which psth to plot indicated by the key in
all_psth['data']`
. If None then all are plotted. - df (DataFrame or dictionary) – The dataframe containing the data.
- window (list of 2 elements) – Time interval to consider, in milliseconds.
- binsize (int) – Bin size in milliseconds.
- plot (bool) – If True then plot.
- event_name (string) – Legend name for event. Default is the actual event name
- conditions_names (TODO) – Legend names for conditions. Default are
the unique values in
df['conditions']
. - ylim (list) – The lower and upper limits for Y.
- colors (list) – The colors for the plot.
Returns: rasters
with keysevent
,conditions
,binsize
,window
, anddata
.rasters['data']
is a dictionary where each value is a raster for each unique entry ofdf['conditions']
.Return type: dict
- event (str) – Column/key name of DataFrame/dictionary
-
get_raster
(event=None, conditions=None, df=None, window=[-100, 500], binsize=10, plot=True, sortby=None, sortorder='descend')[source]¶ Computes the raster and plots it.
Parameters: - event (str) – Column/key name of DataFrame/dictionary “data” which contains event times in milliseconds (e.g. stimulus/trial/fixation onset, etc.)
- conditions (str) – Column/key name of DataFrame/dictionary
data
which contains the conditions by which the trials must be grouped. - df (DataFrame or dictionary) – The dataframe containing the data, or a dictionary with the equivalent structure.
- window (list of 2 elements) – Time interval to consider, in milliseconds.
- binsize (int) – Bin size in milliseconds
- plot (bool) – If True then plot
- sortby (str or list) – If
rate
, sort by firing rate. Iflatency
, sort by peak latency. If a list, integers to be used as sorting indices. - sortorder (str) – Direction to sort, either
descend
orascend
.
Returns: rasters
with keysevent
,conditions
,binsize
,window
, anddata
.rasters['data']
is a dictionary where each value is a raster for each unique entry ofdf['conditions']
.Return type: dict
-
get_spikecounts
(event=None, df=None, window=array([ 50., 100.]))[source]¶ Counts spikes in the dataframe.
Parameters: - event (str) – Column/key name of DataFrame/dictionary
data
which contains event times in milliseconds (e.g. stimulus/trial/fixation onset, etc.) - window (list of 2 elements) – Time interval to consider, in milliseconds.
Returns: An
n x 1
array of spike counts.Return type: array
- event (str) – Column/key name of DataFrame/dictionary
-
plot_psth
(psth, event_name='event_onset', conditions_names=None, cond_id=None, ylim=None, colors=['#F5A21E', '#134B64', '#EF3E34', '#02A68E', '#FF07CD'])[source]¶ Plots PSTH.
Parameters: - psth (dict) – Output of
get_psth()
. - event_name (string) – Legend name for event. Default is the actual event name.
- conditions_names (list of str) – Legend names for conditions.
Default are the keys in
psth['data']
. - cond_id (list) – Which psth to plot indicated by the key in
all_psth['data']`
. If None then all are plotted. - ylim (list) – The lower and upper limits for Y.
- colors (list) – The colors for the plot.
- psth (dict) – Output of
-
plot_raster
(rasters, cond_id=None, cond_name=None, sortby=None, sortorder='descend', cmap='Greys', has_title=True)[source]¶ Plot a single raster.
Parameters: - rasters (dict) – Output of get_raster method
- cond_id (str) – Which raster to plot indicated by the key in
rasters['data']
. If None then all are plotted. - cond_name (str) – Name to appear in the title.
- sortby (str or list) – If
rate
, sort by firing rate. Iflatency
, sort by peak latency. If a list, integers to be used as sorting indices. - sortorder (str) – Direction to sort in, either
descend
orascend
. - cmap (str) – Colormap for raster.
- has_title (bool) – If True then adds title.
PopVis¶
-
class
spykes.plot.popvis.
PopVis
(neuron_list, name='PopVis')[source]¶ Facilitates visualization of neuron population firing activity.
Parameters: neuron_list (list of NeuroVis objects) – The list of neurons to visualize (see the NeuroVis class in spykes.plot.neurovis
).-
n_neurons
¶ int – The number of neurons in the visualization.
-
name
¶ str – The name of this visualization.
-
get_all_psth
(event=None, df=None, conditions=None, window=[-100, 500], binsize=10, conditions_names=None, plot=True, colors=['Blues', 'Reds', 'Greens'])[source]¶ Iterates through all neurons and computes their PSTH’s.
Parameters: - event (str) – Column/key name of DataFrame/dictionary “data” which contains event times in milliseconds (e.g. stimulus/trial/ fixation onset, etc.).
- df (DataFrame or dictionary) – The data to use.
- conditions (str) – Column/key name of DataFrame/dictionary
df
which contains the conditions by which the trials must be grouped - window (list of 2 elements) – Time interval to consider, in milliseconds.
- binsize (int) – Bin size, in milliseconds.
- conditions_names (list of str) – Legend names for conditions.
Default are the unique values in
df['conditions']
. - plot (bool) – If set, automatically plot; otherwise, don’t.
- colors (list) – List of colors for heatmap (only if plot is True).
Returns: With keys
event
,conditions
,binsize
,window
, anddata
. Each entry inpsth['data']
is itself a dictionary with keys of eachcond_id
that correspond to the means for that condition.Return type: dict
-
plot_heat_map
(psth_dict, cond_id=None, conditions_names=None, sortby=None, sortorder='descend', normalize=None, neuron_names=True, colors=None, show=False)[source]¶ Plots heat map for neuron population
Parameters: - psth_dict (dict) – With keys
event
,conditions
,binsize
,window
, anddata
. Each entry inpsth['data']
is itself a dictionary with keys of eachcond_id
that correspond to the means for that condition. - cond_id (str) – Which psth to plot indicated by the key in
all_psth['data']
. If None then all are plotted. - conditions_names (str or list of str) – Name(s) to appear in the title.
- sortby (str or list) – If
rate
, sort by firing rate. Iflatency
, sort by peak latency. If a list or array is provided, it must correspond to integer indices to be used as sorting indices. If no sort order is provided, the data is returned as-is. - sortorder (str) – The direction to sort in, either
descend
orascend
. - normalize (str) – If
all
, divide all PSTHs by highest peak firing rate in all neurons. Ifeach
, divide each PSTH by its own peak firing rate. If None, do not normalize. - neuron_names (bool) – Whether or not to list the names of neurons on the side.
- colors (list of str) – List of colors for the heatmap (as strings).
- show (bool) – If set, show the plot once finished.
- psth_dict (dict) – With keys
-
plot_population_psth
(all_psth=None, event=None, df=None, conditions=None, cond_id=None, window=[-100, 500], binsize=10, conditions_names=None, event_name='event_onset', ylim=None, colors=['#F5A21E', '#134B64', '#EF3E34', '#02A68E', '#FF07CD'], show=False)[source]¶ Plots population PSTH’s.
This involves two steps. First, it normalizes each neuron’s PSTH across the conditions. Second, it averages out and plots population PSTH.
Parameters: - all_psth (dict) – With keys
event
,conditions
,binsize
,window
, anddata
. Each entry inpsth['data']
is itself a dictionary with keys of eachcond_id
that correspond to the means for that condition. - event (str) – Column/key name of the
df
DataFrame/dictionary which contains event times in milliseconds (stimulus/trial/fixation onset, etc.). - df (DataFrame or dictionary) – DataFrame containing the data to plot, or a dictionary corresponding to such a DataFrame.
- conditions (str) – Column/key name of DataFrame/dictionary
df
which contains the conditions by which the trials must be grouped. - cond_id (list) – Which psth to plot indicated by the key in
all_psth['data']`
. IfNone
then all are plotted. - window (list of 2 elements) – Time interval to consider, in milliseconds.
- binsize (int) – Bin size, in milliseconds.
- conditions_names (list) – Legend names for conditions. Default are
the unique values in
df['conditions']
. - event_name (string) – Legend name for event. Default is the actual event name
- ylim (list) – The minimum and maximum values for Y.
- colors (list) – The colors to use for the plot (as strings).
- show (bool) – If set, show the plot once it has been created.
- all_psth (dict) – With keys
-