Sophie

Sophie

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

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

.. _pylab_examples-figlegend_demo:

pylab_examples example code: figlegend_demo.py
==============================================



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

::

    import numpy as np
    import matplotlib.pyplot as plt
    
    fig = plt.figure()
    ax1 = fig.add_axes([0.1, 0.1, 0.4, 0.7])
    ax2 = fig.add_axes([0.55, 0.1, 0.4, 0.7])
    
    x = np.arange(0.0, 2.0, 0.02)
    y1 = np.sin(2*np.pi*x)
    y2 = np.exp(-x)
    l1, l2 = ax1.plot(x, y1, 'rs-', x, y2, 'go')
    
    y3 = np.sin(4*np.pi*x)
    y4 = np.exp(-2*x)
    l3, l4 = ax2.plot(x, y3, 'yd-', x, y3, 'k^')
    
    fig.legend((l1, l2), ('Line 1', 'Line 2'), 'upper left')
    fig.legend((l3, l4), ('Line 3', 'Line 4'), 'upper right')
    plt.show()
    

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