
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/userdemo/connect_simple01.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        Click :ref:`here <sphx_glr_download_gallery_userdemo_connect_simple01.py>`
        to download the full example code

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_userdemo_connect_simple01.py:


================
Connect Simple01
================

A `.ConnectionPatch` can be used to draw a line (possibly with arrow head)
between points defined in different coordinate systems and/or axes.

.. GENERATED FROM PYTHON SOURCE LINES 9-52



.. image:: /gallery/userdemo/images/sphx_glr_connect_simple01_001.png
    :alt: connect simple01
    :class: sphx-glr-single-img





.. code-block:: default


    from matplotlib.patches import ConnectionPatch
    import matplotlib.pyplot as plt

    fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(6, 3))

    # Draw a simple arrow between two points in axes coordinates
    # within a single axes.
    xyA = (0.2, 0.2)
    xyB = (0.8, 0.8)
    coordsA = "data"
    coordsB = "data"
    con = ConnectionPatch(xyA, xyB, coordsA, coordsB,
                          arrowstyle="-|>", shrinkA=5, shrinkB=5,
                          mutation_scale=20, fc="w")
    ax1.plot([xyA[0], xyB[0]], [xyA[1], xyB[1]], "o")
    ax1.add_artist(con)

    # Draw an arrow between the same point in data coordinates,
    # but in different axes.
    xy = (0.3, 0.2)
    con = ConnectionPatch(
        xyA=xy, coordsA=ax2.transData,
        xyB=xy, coordsB=ax1.transData,
        arrowstyle="->", shrinkB=5)
    fig.add_artist(con)

    # Draw a line between the different points, defined in different coordinate
    # systems.
    con = ConnectionPatch(
        # in axes coordinates
        xyA=(0.6, 1.0), coordsA=ax2.transAxes,
        # x in axes coordinates, y in data coordinates
        xyB=(0.0, 0.2), coordsB=ax2.get_yaxis_transform(),
        arrowstyle="-")
    ax2.add_artist(con)

    ax1.set_xlim(0, 1)
    ax1.set_ylim(0, 1)
    ax2.set_xlim(0, .5)
    ax2.set_ylim(0, .5)

    plt.show()


.. _sphx_glr_download_gallery_userdemo_connect_simple01.py:


.. only :: html

 .. container:: sphx-glr-footer
    :class: sphx-glr-footer-example



  .. container:: sphx-glr-download sphx-glr-download-python

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



  .. container:: sphx-glr-download sphx-glr-download-jupyter

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


.. only:: html

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

    Keywords: matplotlib code example, codex, python plot, pyplot
    `Gallery generated by Sphinx-Gallery
    <https://sphinx-gallery.readthedocs.io>`_
