This documentation is for plotting raster plots ONLY. Please refer to the online documentation of pylab, NEURON, and Python to learn more about plotting NEURON/Python data.
1. Python Raster Plots for NEURON/Python Simulations
This section assumes all your cells and parameters have been initialized in Python.
2. Python Raster Plots for NEURON Simulations
This section assumes all your cells and parameters have been initialized in NEURON.
1. Python Raster Plots for NEURON/Python Simulations
Code: Select all
import neuron, matplotlib.pylab as mp
h = neuron.h
Section = h.Section
list_of_cells = [] #this list will contain all the cells
for i in range(50): #assuming you want 50 cells in the population.
list_of_cells.append(Section()) #append the list with NEURON sections (equivalent to creating a cell)
# here you will have to specify cell parameters, network connectivity, import mechanisms, etc.
#create vectors that will record data for the raster plot:
tvec = h.Vector() #time
idvec = h.Vector() #cell number
recording_netcon = h.NetCon(list_of_cells[i].soma(.5)._ref_v, h.nil, sec=list_of_cells[i].soma(.5))
recording_netcon.threshold = -10 #set threshold to a value of your choice
recording_netcon.record(tvec, idvec, i)
h.load_file('stdrun.hoc')
h.tstop = 100 #simulation time in ms
h.run() #run the simulation
#once the simulation is finished, plot using matplotlib:
#you may add titles, axis labels, legends, etc. as well. The how-to is in the pylab documentation
mp.figure(1) #to change the size of the plot use: mp.figure(1, figsize=(20,20))
mp.scatter(tvec, idvec, c='b', marker='+') #you can change the color and marker according to the pylab documentation
mp.savefig('screenshots/raster_plot.png') #this will save the plot - comment out if this is not needed
mp.draw()
mp.show() #this allows you to view the plot - comment out if this not needed
mp.close()
2. Python Raster Plots for NEURON Simulations
Suppose your cells have been appended to a list called 'list_of_cells' and the cells have been appropriately initialized with the desired properties. You must then record the spike trains entirely within NEURON using the following syntax:
Code: Select all
tvec = new Vector()
idvec = new Vector()
proc preprasterplot2() {
for i=0, list_of_cells.count()-1 {
list_of_cells.object(i).soma netcon = new NetCon(&v(0.5), nil, -10, 1, 0)
netcon.record(tvec, idvec, i+1)
}
Lets assume this code is saved to a file called 'neuron.hoc'
Create a python file in the same directory as 'neuron.hoc' with the following code:
Code: Select all
import neuron, matplotlib.pylab as mp
h = neuron.h
Section = h.Section
h.load_file('neuron.hoc')
h.load_file('stdrun.hoc')
h.tstop = 100 #time of simulation in ms
h.run() #run the simulation
#now the plotting code:
mp.figure(1) # to increase the size of the graph use: mp.figure(1, figsize=(20,20))
mp.scatter(h.tvec, h.idvec, c='b', marker='+')
mp.savefig('screenshots/raster_plot.png') #saves the plot – comment if this is not needed
mp.draw()
mp.show() #displays the plot immediately after the simulation is over – comment if this is not needed
mp.close()