
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "examples/plot_with_matplotlib.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        Click :ref:`here <sphx_glr_download_examples_plot_with_matplotlib.py>`
        to download the full example code

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_examples_plot_with_matplotlib.py:


Plotting a Neo object with matplotlib
=====================================

.. GENERATED FROM PYTHON SOURCE LINES 6-43



.. image-sg:: /examples/images/sphx_glr_plot_with_matplotlib_001.png
   :alt: File_plexon_3.plx
   :srcset: /examples/images/sphx_glr_plot_with_matplotlib_001.png
   :class: sphx-glr-single-img


.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    SEG: File_plexon_3.plx






|

.. code-block:: default


    import urllib

    import numpy as np
    import quantities as pq
    from matplotlib import pyplot

    import neo

    distantfile = 'https://web.gin.g-node.org/NeuralEnsemble/ephy_testing_data/raw/master/plexon/File_plexon_3.plx'
    localfile = './File_plexon_3.plx'

    urllib.request.urlretrieve(distantfile, localfile)

    # reader = neo.io.NeuroExplorerIO(filename='File_neuroexplorer_2.nex')
    reader = neo.io.PlexonIO(filename='File_plexon_3.plx')

    bl = reader.read(lazy=False)[0]
    for seg in bl.segments:
        print("SEG: " + str(seg.file_origin))
        fig = pyplot.figure()
        ax1 = fig.add_subplot(2, 1, 1)
        ax2 = fig.add_subplot(2, 1, 2)
        ax1.set_title(seg.file_origin)
        ax1.set_ylabel('arbitrary units')
        mint = 0 * pq.s
        maxt = np.inf * pq.s
        for i, asig in enumerate(seg.analogsignals):
            times = asig.times.rescale('s').magnitude
            asig = asig.magnitude
            ax1.plot(times, asig)

        trains = [st.rescale('s').magnitude for st in seg.spiketrains]
        colors = pyplot.cm.jet(np.linspace(0, 1, len(seg.spiketrains)))
        ax2.eventplot(trains, colors=colors)

    pyplot.show()


.. rst-class:: sphx-glr-timing

   **Total running time of the script:** ( 0 minutes  3.640 seconds)


.. _sphx_glr_download_examples_plot_with_matplotlib.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example


    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: plot_with_matplotlib.py <plot_with_matplotlib.py>`

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: plot_with_matplotlib.ipynb <plot_with_matplotlib.ipynb>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
