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

.. only:: html

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

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

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

.. _sphx_glr_gallery_shapes_and_collections_compound_path.py:


=============
Compound path
=============

Make a compound path -- in this case two simple polygons, a rectangle
and a triangle.  Use ``CLOSEPOLY`` and ``MOVETO`` for the different parts of
the compound path

.. GENERATED FROM PYTHON SOURCE LINES 10-36

.. code-block:: default


    from matplotlib.path import Path
    from matplotlib.patches import PathPatch
    import matplotlib.pyplot as plt

    vertices = []
    codes = []

    codes = [Path.MOVETO] + [Path.LINETO]*3 + [Path.CLOSEPOLY]
    vertices = [(1, 1), (1, 2), (2, 2), (2, 1), (0, 0)]

    codes += [Path.MOVETO] + [Path.LINETO]*2 + [Path.CLOSEPOLY]
    vertices += [(4, 4), (5, 5), (5, 4), (0, 0)]

    path = Path(vertices, codes)

    pathpatch = PathPatch(path, facecolor='None', edgecolor='green')

    fig, ax = plt.subplots()
    ax.add_patch(pathpatch)
    ax.set_title('A compound path')

    ax.autoscale_view()

    plt.show()




.. image:: /gallery/shapes_and_collections/images/sphx_glr_compound_path_001.png
    :alt: A compound path
    :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 37-44

------------

References
""""""""""

The use of the following functions, methods, classes and modules is shown
in this example:

.. GENERATED FROM PYTHON SOURCE LINES 45-53

.. code-block:: default


    import matplotlib
    matplotlib.path
    matplotlib.path.Path
    matplotlib.patches
    matplotlib.patches.PathPatch
    matplotlib.axes.Axes.add_patch
    matplotlib.axes.Axes.autoscale_view




.. rst-class:: sphx-glr-script-out

 Out:

 .. code-block:: none


    <function _AxesBase.autoscale_view at 0x7f73be8de3a0>




.. _sphx_glr_download_gallery_shapes_and_collections_compound_path.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: compound_path.py <compound_path.py>`



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

     :download:`Download Jupyter notebook: compound_path.ipynb <compound_path.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>`_
