Sophie

Sophie

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

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

.. _pylab_examples-findobj_demo:

pylab_examples example code: findobj_demo.py
============================================



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

::

    """
    Recursively find all objects that match some criteria
    """
    import numpy as np
    import matplotlib.pyplot as plt
    import matplotlib.text as text
    
    a = np.arange(0,3,.02)
    b = np.arange(0,3,.02)
    c = np.exp(a)
    d = c[::-1]
    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    plt.plot(a,c,'k--',a,d,'k:',a,c+d,'k')
    plt.legend(('Model length', 'Data length', 'Total message length'),
               'upper center', shadow=True)
    plt.ylim([-1,20])
    plt.grid(False)
    plt.xlabel('Model complexity --->')
    plt.ylabel('Message length --->')
    plt.title('Minimum Message Length')
    
    # match on arbitrary function
    def myfunc(x):
        return hasattr(x, 'set_color') and not hasattr(x, 'set_facecolor')
    
    for o in fig.findobj(myfunc):
        o.set_color('blue')
    
    # match on class instances
    for o in fig.findobj(text.Text):
        o.set_fontstyle('italic')
    
    
    
    plt.show()
    

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