brian2tools.plotting package¶
Package containing plotting modules.
-
brian2tools.plotting.
brian_plot
(brian_obj, axes=None, **kwds)[source]¶ Plot the data of the given object (e.g. a monitor). This function will call an adequate plotting function for the object, e.g.
plot_raster
for aSpikeMonitor
. The plotting may apply heuristics to get a generally useful plot (e.g. for aPopulationRateMonitor
, it will plot the rates smoothed with a Gaussian window of 1 ms), the exact details are subject to change. This function is therefore mostly meant as a quick and easy way to plot an object, for full control use one of the specific plotting functions.Parameters: - brian_obj (object) – The Brian object to plot.
- axes (
Axes
, optional) – TheAxes
instance used for plotting. Defaults toNone
which means that a newAxes
will be created for the plot. - kwds (dict, optional) – Any additional keywords command will be handed over to matplotlib’s
plot
command. This can be used to set plot properties such as thecolor
.
Returns: axes – The
Axes
instance that was used for plotting. This object allows to modify the plot further, e.g. by setting the plotted range, the axis labels, the plot title, etc.Return type:
-
brian2tools.plotting.
add_background_pattern
(axes, hatch='xxx', fill=True, fc=(0.9, 0.9, 0.9), ec=(0.8, 0.8, 0.8), zorder=-10, **kwds)[source]¶ Add a “hatching” pattern to the background of the axes (can be useful to make a difference between “no value” and a value mapped to a color value that is identical to the background color). By default, it uses a cross hatching pattern in gray which can be changed by providing the respective arguments. All additional keyword arguments are passed on to the
Rectangle
initializer.Parameters: - axes (
matplotlib.axes.Axes
) – The axes where the background pattern should be added. - hatch (str, optional) – See
matplotlib.patches.Patch.set_hatch
. Defaults to'xxx'
. - fill (bool, optional) – See
matplotlib.patches.Patch.set_fill
. Defaults toTrue
. - fc (mpl color spec or None or 'none') – See
matplotlib.patches.Patch.set_facecolor
. Defaults to(0.9, 0.9, 0.9)
. - ec (mpl color spec or None or 'none') – See
matplotlib.patches.Patch.set_edgecolor
. Defaults to(0.8, 0.8, 0.8)
. - zorder (int) – See
matplotlib.artist.Artist.set_zorder
. Defaults to-10
.
- axes (
-
brian2tools.plotting.
plot_raster
(spike_indices, spike_times, time_unit=<Mock name='mock.ms' id='140104943437712'>, axes=None, **kwds)[source]¶ Plot a “raster plot”, a plot of neuron indices over spike times. The default marker used for plotting is
'.'
, it can be overriden with themarker
keyword argument.Parameters: - spike_indices (
ndarray
) – The indices of spiking neurons, corresponding to the times given inspike_times
. - spike_times (
Quantity
) – A sequence of spike times. - time_unit (
Unit
, optional) – The unit to use for the time axis. Defaults toms
, but longer simulations could usesecond
, for example. - axes (
Axes
, optional) – TheAxes
instance used for plotting. Defaults toNone
which means that a newAxes
will be created for the plot. - kwds (dict, optional) – Any additional keywords command will be handed over to matplotlib’s
plot
command. This can be used to set plot properties such as thecolor
.
Returns: axes – The
Axes
instance that was used for plotting. This object allows to modify the plot further, e.g. by setting the plotted range, the axis labels, the plot title, etc.Return type: - spike_indices (
-
brian2tools.plotting.
plot_state
(times, values, time_unit=<Mock name='mock.ms' id='140104943437712'>, var_unit=None, var_name=None, axes=None, **kwds)[source]¶ Parameters: - times (
Quantity
) – The array of times for the data points given invalues
. - values (
Quantity
,ndarray
) – The values to plot, either a 1D array with the same length astimes
, or a 2D array withlen(times)
rows. - time_unit (
Unit
, optional) – The unit to use for the time axis. Defaults toms
, but longer simulations could usesecond
, for example. - var_unit (
Unit
, optional) – The unit to use to plot thevalues
(e.g.mV
for a membrane potential). If none is given (the default), an attempt is made to find a good scale automatically based on thevalues
. - var_name (str, optional) – The name of the variable that is plotted. Used for the axis label.
- axes (
Axes
, optional) – TheAxes
instance used for plotting. Defaults toNone
which means that a newAxes
will be created for the plot. - kwds (dict, optional) – Any additional keywords command will be handed over to matplotlib’s
plot
command. This can be used to set plot properties such as thecolor
.
Returns: axes – The
Axes
instance that was used for plotting. This object allows to modify the plot further, e.g. by setting the plotted range, the axis labels, the plot title, etc.Return type: - times (
-
brian2tools.plotting.
plot_rate
(times, rate, time_unit=<Mock name='mock.ms' id='140104943437712'>, rate_unit=<Mock name='mock.Hz' id='140105029554832'>, axes=None, **kwds)[source]¶ Parameters: - times (
Quantity
) – The time points at which therate
is measured. - rate (
Quantity
) – The population rate for each time point intimes
- time_unit (
Unit
, optional) – The unit to use for the time axis. Defaults toms
, but longer simulations could usesecond
, for example. - time_unit – The unit to use for the rate axis. Defaults to
Hz
. - axes (
Axes
, optional) – TheAxes
instance used for plotting. Defaults toNone
which means that a newAxes
will be created for the plot. - kwds (dict, optional) – Any additional keywords command will be handed over to matplotlib’s
plot
command. This can be used to set plot properties such as thecolor
.
Returns: axes – The
Axes
instance that was used for plotting. This object allows to modify the plot further, e.g. by setting the plotted range, the axis labels, the plot title, etc.Return type: - times (
-
brian2tools.plotting.
plot_morphology
(morphology, plot_3d=None, show_compartments=False, show_diameter=False, colors=('darkblue', 'darkred'), values=None, value_norm=(None, None), value_colormap='hot', value_colorbar=True, value_unit=None, axes=None)[source]¶ Plot a given
Morphology
in 2D or 3D.Parameters: - morphology (
Morphology
) – The morphology to plot - plot_3d (bool, optional) – Whether to plot the morphology in 3D or in 2D. If not set (the default) a morphology where all z values are 0 is plotted in 2D, otherwise it is plot in 3D.
- show_compartments (bool, optional) – Whether to plot a dot at the center of each compartment. Defaults to
False
. - show_diameter (bool, optional) – Whether to plot the compartments with the diameter given in the
morphology. Defaults to
False
. - colors (sequence of color specifications) – A list of colors that is cycled through for each new section. Can be
any color specification that matplotlib understands (e.g. a string such
as
'darkblue'
or a tuple such as(0, 0.7, 0)
. - values (Quantity, optional) – Values to fill compartment patches with a color that corresponds to their given value.
- value_norm (tuple or callable, optional) – Normalization function to scale the displayed values. Can be a tuple
of a minimum and a maximum value (where either of them can be
None
to denote taking the minimum/maximum from the data) or a function that takes a value and returns the scaled value (e.g. as returned bymatplotlib.colors.PowerNorm
). For a tuple of values, will usematplotlib.colors.Normalize```(vmin, vmax, clip=True)``
with the given(vmin, vmax)
values. - value_colormap (str or matplotlib.colors.Colormap, optional) – Desired colormap for plots. Either the name of a standard colormap
or a
matplotlib.colors.Colormap
instance. Defaults to'hot'
. Note that this usesmatplotlib
color maps even for 3D plots with Mayavi. - value_colorbar (bool or dict, optional) – Whether to add a colorbar for the
values
. Defaults toTrue
, but will be ignored if novalues
are provided. Can also be a dictionary with the keyword arguments for matplotlib’scolorbar
method (2D plot), or for Mayavi’sscalarbar
method (3D plot). - value_unit (
Unit
, optional) – AUnit
to rescale the values for display in the colorbar. Does not have any visible effect if no colorbar is used. If not specified, will try to determine the “best unit” to itself. - axes (
Axes
orScene
, optional) – A matplotlibAxes
(for 2D plots) or mayaviScene
( for 3D plots) instance, where the plot will be added.
Returns: axes – The
Axes
orScene
instance that was used for plotting. This object allows to modify the plot further, e.g. by setting the plotted range, the axis labels, the plot title, etc.Return type: - morphology (
-
brian2tools.plotting.
plot_dendrogram
(morphology, axes=None)[source]¶ Plot a “dendrogram” of a morphology, i.e. an abstract representation which visualizes the branching structure and the length of each section.
Parameters: - morphology (
Morphology
) – The morphology to visualize. - axes (
Axes
, optional) – TheAxes
instance used for plotting. Defaults toNone
which means that a newAxes
will be created for the plot.
Returns: axes – The
Axes
instance that was used for plotting. This object allows to modify the plot further, e.g. by setting the plotted range, the axis labels, the plot title, etc.Return type: - morphology (
-
brian2tools.plotting.
plot_synapses
(sources, targets, values=None, var_unit=None, var_name=None, plot_type='scatter', axes=None, **kwds)[source]¶ Parameters: - sources (
ndarray
of int) – The source indices of the connections (as returned bySynapses.i
). - targets (
ndarray
of int) – The target indices of the connections (as returned bySynapses.j
). - values (
Quantity
,ndarray
) – The values to plot, a 1D array of the same size assources
andtargets
. - var_unit (
Unit
, optional) – The unit to use to plot thevalues
(e.g.mV
for a membrane potential). If none is given (the default), an attempt is made to find a good scale automatically based on thevalues
. - var_name (str, optional) – The name of the variable that is plotted. Used for the axis label.
- plot_type ({
'scatter'
,'image'
,'hexbin'
}, optional) – What type of plot to use. Can be'scatter'
(the default) to draw a scatter plot,'image'
to display the connections as a matrix or'hexbin'
to display a 2D histogram using matplotlib’shexbin
function. For a large number of synapses,'scatter'
will be very slow. Similarly, an'image'
plot will use a lot of memory for connections between two large groups. For a small number of neurons and synapses,'hexbin'
will be hard to interpret. - axes (
Axes
, optional) – TheAxes
instance used for plotting. Defaults toNone
which means that a newAxes
will be created for the plot. - kwds (dict, optional) – Any additional keywords command will be handed over to the respective
matplotlib command (
scatter
if theplot_type
is'scatter'
,imshow
for'image'
, andhexbin
for'hexbin'
). This can be used to set plot properties such as themarker
.
Returns: axes – The
Axes
instance that was used for plotting. This object allows to modify the plot further, e.g. by setting the plotted range, the axis labels, the plot title, etc.Return type: - sources (