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 a SpikeMonitor. The plotting may apply heuristics to get a generally useful plot (e.g. for a PopulationRateMonitor, 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) – The Axes instance used for plotting. Defaults to None which means that a new Axes 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 the color.
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:

Axes

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:
brian2tools.plotting.plot_raster(spike_indices, spike_times, time_unit=<Mock name='mock.ms' id='140308607353488'>, 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 the marker keyword argument.

Parameters:
  • spike_indices (ndarray) – The indices of spiking neurons, corresponding to the times given in spike_times.
  • spike_times (Quantity) – A sequence of spike times.
  • time_unit (Unit, optional) – The unit to use for the time axis. Defaults to ms, but longer simulations could use second, for example.
  • axes (Axes, optional) – The Axes instance used for plotting. Defaults to None which means that a new Axes 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 the color.
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:

Axes

brian2tools.plotting.plot_state(times, values, time_unit=<Mock name='mock.ms' id='140308607353488'>, var_unit=None, var_name=None, axes=None, **kwds)[source]
Parameters:
  • times (Quantity) – The array of times for the data points given in values.
  • values (Quantity, ndarray) – The values to plot, either a 1D array with the same length as times, or a 2D array with len(times) rows.
  • time_unit (Unit, optional) – The unit to use for the time axis. Defaults to ms, but longer simulations could use second, for example.
  • var_unit (Unit, optional) – The unit to use to plot the values (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 the values.
  • var_name (str, optional) – The name of the variable that is plotted. Used for the axis label.
  • axes (Axes, optional) – The Axes instance used for plotting. Defaults to None which means that a new Axes 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 the color.
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:

Axes

brian2tools.plotting.plot_rate(times, rate, time_unit=<Mock name='mock.ms' id='140308607353488'>, rate_unit=<Mock name='mock.Hz' id='140308607354512'>, axes=None, **kwds)[source]
Parameters:
  • times (Quantity) – The time points at which the rate is measured.
  • rate (Quantity) – The population rate for each time point in times
  • time_unit (Unit, optional) – The unit to use for the time axis. Defaults to ms, but longer simulations could use second, for example.
  • time_unit – The unit to use for the rate axis. Defaults to Hz.
  • axes (Axes, optional) – The Axes instance used for plotting. Defaults to None which means that a new Axes 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 the color.
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:

Axes

brian2tools.plotting.plot_morphology(morphology, plot_3d=None, show_compartments=False, show_diameter=False, colors=('darkblue', 'darkred'), 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).
  • axes (Axes or Scene, optional) – A matplotlib Axes (for 2D plots) or mayavi Scene ( for 3D plots) instance, where the plot will be added.
Returns:

axes – The Axes or Scene 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:

Axes or Scene

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) – The Axes instance used for plotting. Defaults to None which means that a new Axes 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:

Axes

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 by Synapses.i).
  • targets (ndarray of int) – The target indices of the connections (as returned by Synapses.j).
  • values (Quantity, ndarray) – The values to plot, a 1D array of the same size as sources and targets.
  • var_unit (Unit, optional) – The unit to use to plot the values (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 the values.
  • 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’s hexbin 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) – The Axes instance used for plotting. Defaults to None which means that a new Axes will be created for the plot.
  • kwds (dict, optional) – Any additional keywords command will be handed over to the respective matplotlib command (scatter if the plot_type is 'scatter', imshow for 'image', and hexbin for 'hexbin'). This can be used to set plot properties such as the marker.
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:

Axes