brian2tools.plotting package¶
Package containing plotting modules.
- 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
Rectangleinitializer.- 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.
- 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_rasterfor 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.When a
StateMonitorthat records several variables is given, a column of subplots sharing the time axis is created automatically.- Parameters:
brian_obj (object) – The Brian object to plot.
axes (
Axesor array-like of Axes, optional) – TheAxesinstance used for plotting. Defaults toNonewhich means that a newAxeswill be created for the plot. For a multi-variableStateMonitor, pass an array-like ofAxeswith one entry per recorded variable.kwds (dict, optional) –
Any additional keywords command will be handed over to matplotlib’s
plotcommand. This can be used to set plot properties such as thecolor.For multi-variable
StateMonitorobjects,var_nameandvar_unitmay be dictionaries keyed by variable name, e.g.var_name={'v': 'membrane potential', 'I': 'input current'}.
- Returns:
axes – The
Axesinstance(s) used for plotting. A list is returned when multiple state variables are plotted.- Return type:
- brian2tools.plotting.plot_dendrogram(morphology, axes=None, **kwds)[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) – TheAxesinstance used for plotting. Defaults toNonewhich means that a newAxeswill be created for the plot.**kwds – Any additional keyword arguments are passed to matplotlib’s
plot,vlines, andhlinescalls. Only arguments accepted by all three functions should be used (e.g.color,alpha,linewidth).
- Returns:
axes – The
Axesinstance 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.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
Morphologyin 2D or 3D.- Parameters:
morphology (
Morphology) – The morphology to plotplot_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
Noneto 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.Colormapinstance. Defaults to'hot'. Note that this usesmatplotlibcolor 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 novaluesare provided. Can also be a dictionary with the keyword arguments for matplotlib’scolorbarmethod (2D plot), or for Mayavi’sscalarbarmethod (3D plot).value_unit (
Unit, optional) – AUnitto 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 (
AxesorScene, optional) – A matplotlibAxes(for 2D plots) or mayaviScene( for 3D plots) instance, where the plot will be added.
- Returns:
axes – The
AxesorSceneinstance 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.plot_raster(spike_indices, spike_times, time_unit=<Mock name='mock.ms' id='130266780174144'>, 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 themarkerkeyword 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) – TheAxesinstance used for plotting. Defaults toNonewhich means that a newAxeswill be created for the plot.kwds (dict, optional) – Any additional keywords command will be handed over to matplotlib’s
plotcommand. This can be used to set plot properties such as thecolor.
- Returns:
axes – The
Axesinstance 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.plot_rate(times, rate, time_unit=<Mock name='mock.ms' id='130266780174144'>, rate_unit=<Mock name='mock.Hz' id='130266780174336'>, axes=None, **kwds)[source]¶
- Parameters:
times (
Quantity) – The time points at which therateis measured.rate (
Quantity) – The population rate for each time point intimestime_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) – TheAxesinstance used for plotting. Defaults toNonewhich means that a newAxeswill be created for the plot.kwds (dict, optional) – Any additional keywords command will be handed over to matplotlib’s
plotcommand. This can be used to set plot properties such as thecolor.
- Returns:
axes – The
Axesinstance 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.plot_state(times, values, time_unit=<Mock name='mock.ms' id='130266780174144'>, 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.mVfor 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) – TheAxesinstance used for plotting. Defaults toNonewhich means that a newAxeswill be created for the plot.kwds (dict, optional) – Any additional keywords command will be handed over to matplotlib’s
plotcommand. This can be used to set plot properties such as thecolor.
- Returns:
axes – The
Axesinstance 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.plot_synapses(sources, targets, values=None, var_unit=None, var_name=None, plot_type='scatter', axes=None, **kwds)[source]¶
- Parameters:
sources (
ndarrayof int) – The source indices of the connections (as returned bySynapses.i).targets (
ndarrayof 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 assourcesandtargets.var_unit (
Unit, optional) – The unit to use to plot thevalues(e.g.mVfor 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’shexbinfunction. 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) – TheAxesinstance used for plotting. Defaults toNonewhich means that a newAxeswill be created for the plot.kwds (dict, optional) – Any additional keywords command will be handed over to the respective matplotlib command (
scatterif theplot_typeis'scatter',imshowfor'image', andhexbinfor'hexbin'). This can be used to set plot properties such as themarker.
- Returns:
axes – The
Axesinstance 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: