Sophie

Sophie

distrib > Mandriva > 2010.2 > i586 > media > contrib-backports > by-pkgid > a44f8c7e78ee9c5838c1fb080c9e7630 > files > 1359

python-matplotlib-doc-1.1.1-1mdv2010.1.noarch.rpm

.. _pylab_examples-loadrec:

pylab_examples example code: loadrec.py
=======================================



.. plot:: /home/mandrake/rpm/BUILD/matplotlib-1.1.1/doc/mpl_examples/pylab_examples/loadrec.py

::

    from matplotlib import mlab
    from pylab import figure, show
    import matplotlib.cbook as cbook
    
    datafile = cbook.get_sample_data('msft.csv', asfileobj=False)
    print 'loading', datafile
    a = mlab.csv2rec(datafile)
    a.sort()
    print a.dtype
    
    fig = figure()
    ax = fig.add_subplot(111)
    ax.plot(a.date, a.adj_close, '-')
    fig.autofmt_xdate()
    
    # if you have xlwt installed, you can output excel
    try:
        import mpl_toolkits.exceltools as exceltools
        exceltools.rec2excel(a, 'test.xls')
    except ImportError:
        pass
    show()
    

Keywords: python, matplotlib, pylab, example, codex (see :ref:`how-to-search-examples`)