Most plotting should be done with the PyLab commands, all of which are loaded when you import Brian. See:
for help on PyLab. The scientific library Scipy is also automatically imported by the instruction from brian import *.
The most useful plotting instruction is the Pylab function plot. A typical use with Brian is:
plot(t/ms,vm/mV)
where t is a vector of times with units ms and vm is a vector of voltage values with units mV. To display the figures on the screen, the function show() must be called once (this should be the last line of your script), except when using IPython with the Pylab mode (ipython -pylab).
Brian currently defines just two plotting functions of its own, raster_plot() and hist_plot(). In addition, the StateMonitor object has a plot() method.
Spike trains recorded by a SpikeMonitor can be displayed as raster plots:
S=SpikeMonitor(group)
...
raster_plot(S)
Usual options of the plot command can also be passed to raster_plot(). One may also pass several spike monitors as arguments.
State values recorded by a StateMonitor can also be plotted as follows:
M = StateMonitor(group, 'V', record=[0,1,2])
...
M.plot()
Both raster_plot() and StateMonitor.plot() have real-time versions which update as the simulation runs, for example:
G = NeuronGroup(...)
spikemon = SpikeMonitor(G)
statemon = StateMonitor(G, 'V', record=range(5))
ion()
subplot(211)
raster_plot(spikemon, refresh=10*ms, showlast=200*ms)
subplot(212)
statemon.plot(refresh=10*ms, showlast=200*ms)
run(1*second)
ioff()
show()
The ion() and ioff() command activate and deactivate Pylab’s interactive plotting mode. The refresh parameter specifies how often (in simulation time) to refresh the plot - smaller values will slow down the simulation. The showlast option only plots the most recent values.
With some IDEs, you may need to do something like the following at the beginning of your script to make interactive mode work:
import matplotlib
matplotlib.use('WXAgg')
This is because the default graphical backend can sometimes interact badly with the IDE. Other options to try are GTKAgg, QTAgg, TkAgg.
Here are a few functions to analyse first and second order statistical properties of spike trains, defined as ordered lists of spike times:
These functions return NaN (not a number) when a spike train is empty.