simple_plot_with_matplotlib.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. """
  2. This is an example for plotting a Neo object with matplotlib.
  3. """
  4. import urllib
  5. import numpy as np
  6. import quantities as pq
  7. from matplotlib import pyplot
  8. import neo
  9. distantfile = 'https://web.gin.g-node.org/NeuralEnsemble/ephy_testing_data/raw/master/plexon/File_plexon_3.plx'
  10. localfile = './File_plexon_3.plx'
  11. urllib.request.urlretrieve(distantfile, localfile)
  12. # reader = neo.io.NeuroExplorerIO(filename='File_neuroexplorer_2.nex')
  13. reader = neo.io.PlexonIO(filename='File_plexon_3.plx')
  14. bl = reader.read(lazy=False)[0]
  15. for seg in bl.segments:
  16. print("SEG: " + str(seg.file_origin))
  17. fig = pyplot.figure()
  18. ax1 = fig.add_subplot(2, 1, 1)
  19. ax2 = fig.add_subplot(2, 1, 2)
  20. ax1.set_title(seg.file_origin)
  21. ax1.set_ylabel('arbitrary units')
  22. mint = 0 * pq.s
  23. maxt = np.inf * pq.s
  24. for i, asig in enumerate(seg.analogsignals):
  25. times = asig.times.rescale('s').magnitude
  26. asig = asig.magnitude
  27. ax1.plot(times, asig)
  28. trains = [st.rescale('s').magnitude for st in seg.spiketrains]
  29. colors = pyplot.cm.jet(np.linspace(0, 1, len(seg.spiketrains)))
  30. ax2.eventplot(trains, colors=colors)
  31. pyplot.show()