

.. _sphx_glr_gallery_axes_grid1_parasite_simple.py:


===============
Parasite Simple
===============





.. image:: /gallery/axes_grid1/images/sphx_glr_parasite_simple_001.png
    :align: center





.. code-block:: python

    from mpl_toolkits.axes_grid1 import host_subplot
    import matplotlib.pyplot as plt

    host = host_subplot(111)

    par = host.twinx()

    host.set_xlabel("Distance")
    host.set_ylabel("Density")
    par.set_ylabel("Temperature")

    p1, = host.plot([0, 1, 2], [0, 1, 2], label="Density")
    p2, = par.plot([0, 1, 2], [0, 3, 2], label="Temperature")

    leg = plt.legend()

    host.yaxis.get_label().set_color(p1.get_color())
    leg.texts[0].set_color(p1.get_color())

    par.yaxis.get_label().set_color(p2.get_color())
    leg.texts[1].set_color(p2.get_color())

    plt.show()

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



.. container:: sphx-glr-footer


  .. container:: sphx-glr-download

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



  .. container:: sphx-glr-download

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

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

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