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

.. only:: html

    .. meta::
        :keywords: codex

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

        :ref:`Go to the end <sphx_glr_download_gallery_shapes_and_collections_patch_collection.py>`
        to download the full example code.

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

.. _sphx_glr_gallery_shapes_and_collections_patch_collection.py:


============================
Circles, Wedges and Polygons
============================

This example demonstrates how to use `.collections.PatchCollection`.

See also :doc:`/gallery/shapes_and_collections/artist_reference`, which instead
adds each artist separately to its own Axes.

.. GENERATED FROM PYTHON SOURCE LINES 11-63

.. code-block:: Python


    import matplotlib.pyplot as plt
    import numpy as np

    from matplotlib.collections import PatchCollection
    from matplotlib.patches import Circle, Polygon, Wedge

    # Fixing random state for reproducibility
    np.random.seed(19680801)


    fig, ax = plt.subplots()

    resolution = 50  # the number of vertices
    N = 3
    x = np.random.rand(N)
    y = np.random.rand(N)
    radii = 0.1*np.random.rand(N)
    patches = []
    for x1, y1, r in zip(x, y, radii):
        circle = Circle((x1, y1), r)
        patches.append(circle)

    x = np.random.rand(N)
    y = np.random.rand(N)
    radii = 0.1*np.random.rand(N)
    theta1 = 360.0*np.random.rand(N)
    theta2 = 360.0*np.random.rand(N)
    for x1, y1, r, t1, t2 in zip(x, y, radii, theta1, theta2):
        wedge = Wedge((x1, y1), r, t1, t2)
        patches.append(wedge)

    # Some limiting conditions on Wedge
    patches += [
        Wedge((.3, .7), .1, 0, 360),             # Full circle
        Wedge((.7, .8), .2, 0, 360, width=0.05),  # Full ring
        Wedge((.8, .3), .2, 0, 45),              # Full sector
        Wedge((.8, .3), .2, 45, 90, width=0.10),  # Ring sector
    ]

    for i in range(N):
        polygon = Polygon(np.random.rand(N, 2), closed=True)
        patches.append(polygon)

    colors = 100 * np.random.rand(len(patches))
    p = PatchCollection(patches, alpha=0.4)
    p.set_array(colors)
    ax.add_collection(p)
    fig.colorbar(p, ax=ax)

    plt.show()




.. image-sg:: /gallery/shapes_and_collections/images/sphx_glr_patch_collection_001.png
   :alt: patch collection
   :srcset: /gallery/shapes_and_collections/images/sphx_glr_patch_collection_001.png, /gallery/shapes_and_collections/images/sphx_glr_patch_collection_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 64-77

.. admonition:: References

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

   - `matplotlib.patches`
   - `matplotlib.patches.Circle`
   - `matplotlib.patches.Wedge`
   - `matplotlib.patches.Polygon`
   - `matplotlib.collections.PatchCollection`
   - `matplotlib.collections.Collection.set_array`
   - `matplotlib.axes.Axes.add_collection`
   - `matplotlib.figure.Figure.colorbar`


.. _sphx_glr_download_gallery_shapes_and_collections_patch_collection.py:

.. only:: html

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

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

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

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

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

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: patch_collection.zip <patch_collection.zip>`


.. only:: html

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

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
