0

I'm trying to create a raster plot of neural spike data using a numpy array given to me. The array has 2 columns such that the 1st column represents the neuron ID (which should appear on the y-axis) and the 2nd column represents the time of the spike (time will x-axis). Each row of the 2 columns is an individual spike. So if the 3rd column is (100, 200) that means the 3rd spike to be measured is by neuron no. 100 at time 200.

import matplotlib.pyplot as pyplot
import numpy as np


spike_data = np.load('spike_train_082019.npy')

pyplot.imshow(spike_data, cmap='Greys')
pyplot.show()

This is what I get: https://i.stack.imgur.com/lqrI5.jpg

Completely empty. Do I need to "parse" the axes of the numpy array? Can I just feed the loaded array into the imshow function? Any help appreciated.

1st edit: This is what I want to do, but no plot shows up at all now...

import numpy as np

spike_data = np.load('spike_train_082019.npy')

unit_id = spike_data[:,0]
spike_time = spike_data[:,1]

pyplot.scatter(spike_time, unit_id)
pyplot.show()
  • You have an array with some millions of rows, and two columns. If you plot that as image, it will be 7 million times taller than wide - which is what you see in your figure. You can add `aspect="auto"` to the `imshow` call to get the plot fit into the figure, but I strongly doubt the result is what you're after. Yet, I don't quite understand what you want to show. – ImportanceOfBeingErnest Aug 20 '19 at 22:22
  • Oh I see. So the millions of “rows” aren’t what I’m really after. Essentially, I want a neuron ID vs time plot on y and x axes, respectively. The x-axis values are given by the values in the first column and the y-axis values are given by the corresponding values in the 2nd columns. It sounds like I have to somehow “parse” out the data because the current imshow function is just spitting out an exact replica of the numpy file. Do you know how I can go about doing this? – NapoleonBonaparte Aug 21 '19 at 00:01
  • `pyplot.plot(*spike_data.T)`? – ImportanceOfBeingErnest Aug 21 '19 at 00:04
  • So your suggestion created this massive blue expanse of a plot (lol). I've gone ahead and edited my original post to reflect what I "want" to accomplish even though no plot actually shows up. Anywhere you see i went wrong? – NapoleonBonaparte Aug 21 '19 at 01:59
  • So, I got the exact same output as your suggestion. (https://imgur.com/EhZVLgM) I'm guessing the blue are all the dots/points? Is there any way I can make this plot look more like a proper raster plot like (https://imgur.com/ahVXuEw) using eventplot? – NapoleonBonaparte Aug 21 '19 at 02:08
  • HOLY I DID IT! (https://imgur.com/8jQ7kx9) I just had to set the radius to a super small value. Could you explain what the asterisk and ".T" do for the spike_data argument in your suggestion? – NapoleonBonaparte Aug 21 '19 at 02:21
  • This is just a compact way of writing what you did in your first edit. – ImportanceOfBeingErnest Aug 21 '19 at 09:06
  • Right, but is there anywhere I can read up on the notation? I tried to find what an asterisk does for pyplot.plot but couldn’t find anything online .. – NapoleonBonaparte Aug 21 '19 at 14:17
  • The asterix has nothing to do with pyplot. It's for argument unpacking. See https://stackoverflow.com/questions/36901/what-does-double-star-asterisk-and-star-asterisk-do-for-parameters – ImportanceOfBeingErnest Aug 21 '19 at 14:24
  • Oh I see. Thank you so much. And where can I find what the “.T” does at the end of “spike_data”? – NapoleonBonaparte Aug 21 '19 at 14:27
  • https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.T.html – ImportanceOfBeingErnest Aug 21 '19 at 14:51
  • Perfect! Thank you so much for you help on my first question here. – NapoleonBonaparte Aug 21 '19 at 14:52

0 Answers0