How to make a raster plot of spikes in a network

A collection of noteworthy items selected by our moderators from discussions about making and using models with NEURON.

Moderators: wwlytton, tom_morse

Post Reply
Site Admin
Posts: 5822
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine

How to make a raster plot of spikes in a network

Post by ted »

This is very easy with the NetCon class's record() method-- ... tml#record
In particular, I refer to the netcon.record(tvec, idvec, id) syntax.

For example, suppose your model neurons have been appended to a List called cells, and
that each one has its spike trigger zone at its soma. Then

Code: Select all

objref timevec, idvec, recncs, tobj, nil
timevec = new Vector()
idvec = new Vector()
recncs = new List()
for i=0,cells.count()-1 {
  cells.object(i).soma tobj = new NetCon(&v(0.5), nil)
  tobj.record(timevec, idvec, i+1) // so all the spike rasters lie above the x axis
objref tobj // so we don't accidentally mess up the last NetCon
If you are recording spikes from artificial spiking cells, the syntax for setting up the NetCon
changes from this form
section netcon = new NetCon(&v(x), target)
to the simpler form
netcon = new NetCon(source, target)
That is, replace the statement
cells.object(i).soma tobj = new NetCon(&v(0.5), nil)
tobj = new NetCon(cells.object(i), nil)

Now all you have to do is run a simulation, then after the end of the simulation, pop up a
new Graph object, and use the Vector class's mark() method to draw vertical bars | --see ... .html#mark

Code: Select all

objref g
proc plotraster() {
  g = new Graph()
  idvec.mark(g, timevec, "|")

proc myrun() {

// call myrun() to launch a simulation and generate a raster plot
Further refinements are possible, e.g. control of position and scaling of the raster plot,
or implementing a dynamically-updated raster plot, but this should be enough to get you
Post Reply