simple_plot_with_matplotlib.py 1.3 KB

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