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

    Click :ref:`here <sphx_glr_download_gallery_misc_plotfile_demo.py>` to download the full example code
.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_misc_plotfile_demo.py:


=============
Plotfile Demo
=============

Example use of ``plotfile`` to plot data directly from a file.




.. rst-class:: sphx-glr-horizontal


    *

      .. image:: /gallery/misc/images/sphx_glr_plotfile_demo_001.png
            :class: sphx-glr-multi-img

    *

      .. image:: /gallery/misc/images/sphx_glr_plotfile_demo_002.png
            :class: sphx-glr-multi-img

    *

      .. image:: /gallery/misc/images/sphx_glr_plotfile_demo_003.png
            :class: sphx-glr-multi-img

    *

      .. image:: /gallery/misc/images/sphx_glr_plotfile_demo_004.png
            :class: sphx-glr-multi-img

    *

      .. image:: /gallery/misc/images/sphx_glr_plotfile_demo_005.png
            :class: sphx-glr-multi-img

    *

      .. image:: /gallery/misc/images/sphx_glr_plotfile_demo_006.png
            :class: sphx-glr-multi-img

    *

      .. image:: /gallery/misc/images/sphx_glr_plotfile_demo_007.png
            :class: sphx-glr-multi-img

    *

      .. image:: /gallery/misc/images/sphx_glr_plotfile_demo_008.png
            :class: sphx-glr-multi-img





.. code-block:: python

    import matplotlib.pyplot as plt
    import numpy as np

    import matplotlib.cbook as cbook

    fname = cbook.get_sample_data('msft.csv', asfileobj=False)
    fname2 = cbook.get_sample_data('data_x_x2_x3.csv', asfileobj=False)

    # test 1; use ints
    plt.plotfile(fname, (0, 5, 6))

    # test 2; use names
    plt.plotfile(fname, ('date', 'volume', 'adj_close'))

    # test 3; use semilogy for volume
    plt.plotfile(fname, ('date', 'volume', 'adj_close'),
                 plotfuncs={'volume': 'semilogy'})

    # test 4; use semilogy for volume
    plt.plotfile(fname, (0, 5, 6), plotfuncs={5: 'semilogy'})

    # test 5; single subplot
    plt.plotfile(fname, ('date', 'open', 'high', 'low', 'close'), subplots=False)

    # test 6; labeling, if no names in csv-file
    plt.plotfile(fname2, cols=(0, 1, 2), delimiter=' ',
                 names=['$x$', '$f(x)=x^2$', '$f(x)=x^3$'])

    # test 7; more than one file per figure--illustrated here with a single file
    plt.plotfile(fname2, cols=(0, 1), delimiter=' ')
    plt.plotfile(fname2, cols=(0, 2), newfig=False,
                 delimiter=' ')  # use current figure
    plt.xlabel(r'$x$')
    plt.ylabel(r'$f(x) = x^2, x^3$')

    # test 8; use bar for volume
    plt.plotfile(fname, (0, 5, 6), plotfuncs={5: 'bar'})

    plt.show()


.. _sphx_glr_download_gallery_misc_plotfile_demo.py:


.. only :: html

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



  .. container:: sphx-glr-download

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



  .. container:: sphx-glr-download

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


.. only:: html

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

    Keywords: matplotlib code example, codex, python plot, pyplot
    `Gallery generated by Sphinx-Gallery
    <https://sphinx-gallery.readthedocs.io>`_
