![]() This function can be used for drawing a vertical line anywhere in a Matplotlib plot. Instead, we use the ax.vlines() method (there is also a plt.vlines() function, if using the procedural approach to plotting). That is, we’re not using the plt.plot() function or ax.plot() method. One thing to notice in the code for this plot is that it’s kind of “hacking” Matplotlib functions to generate the plot. You can see that we have a plot with vertical lines (in Matplotlib’s default colour, blue) indicating the spike times. Since spike_times contains the time points of our spikes, we can use the following code to draw an object-oriented plot in Matplotlib: The y axis is shown as a continuous scale (the default in matplotlib), but of course the actual values can only be 0 or 1. Below we generate a raster plot, with time on the x axis, and the spikes as vertical lines. It is more intuitive for most people to see a timeline with spikes marked at particular time points, than to read a list of index values. Visualization is an effective way of making the data more interpretable. Visualizing a Spike Train: Raster Plots # The i right at the start of the list comprehension means that, if any value of x is a 1, then the index of its list position, i, is added to the spike_times list.įor a detailed overview of list comprehension, check out this DataCamp tutorial. The for statement followed by the if conditional is equivalent to nesting the if statement inside the for loop in the previous example. This allows us to retrieve the index (timing) of only values when that represent spikes (recall we defined spike_value as 1). ![]() To the end of this is added a conditional, if x = spike_value. In this case, they are x, which is one value in spike_train, and i, the enumeration variable that stores the current position in the list (iteration through the loop). The enumerate() function enumerates (counts) the items as it goes through a loop, so each time through the loop we have two variables being tracked. It’s a useful and compact way to iterate over some set of items to get them into a list. Take some time to break this down and understand it - there’s a lot going on! Recall that list comprehension is used to create a for loop in a single line, and return a list. This is a slightly more complicated list comprehension than we’ve seen in the past. Each value represents an evenly-spaced point in time (e.g., every 1 ms), where 0 encodes time points at which no action potential was detected, and 1 represents times when action potentials occurred: We can store the data from each trial in a list, spike_train. Data was sampled from the electrode every millisecond. On each trial, recording was started and then the 550 nm light was turned on 4 ms later, for a duration of 10 ms. When light of that wavelength is directed at the neuron, it tends to fire.įor this hypothetical experiment, we used an electrode to record action potentials from this optogenetically-engineered neuron to confirm that it tends to fire in response to 550 nm light. Imagine an experiment involving a neuron that was genetically engineered for optogenetics, meaning that it expresses genes sensitive to a specific wavelength of light (550 nm, which is green to learn more about optogenetics, check out this video by Prof. # Import libraries we'll need import matplotlib.pyplot as plt import numpy as np Our first spike train # Reading and Visualizing Structural MRI Data.Averaging ERPs: Creating MNE Evoked objects.Working with Multielectrode Data in pandas.Effects of Light Intensity on Spike Rate.Basic Statistics in Python: t tests with SciPy.Accessibility and Human Factors in Plotting.Procedural versus Object-Oriented Plotting in Matplotlib.Introduction to Plotting with Matplotlib.Introduction to Jupyter Notebooks in CoCalc.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |