

.. _sphx_glr_gallery_pylab_examples_findobj_demo.py:


============
Findobj Demo
============

Recursively find all objects that match some criteria




.. image:: /gallery/pylab_examples/images/sphx_glr_findobj_demo_001.png
    :align: center





.. code-block:: python

    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, ax = plt.subplots()
    plt.plot(a, c, 'k--', a, d, 'k:', a, c + d, 'k')
    plt.legend(('Model length', 'Data length', 'Total message length'),
               loc='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()

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



.. container:: sphx-glr-footer


  .. container:: sphx-glr-download

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



  .. container:: sphx-glr-download

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

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

    `Generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_
