
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/shapes_and_collections/ellipse_demo.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_ellipse_demo.py>`
        to download the full example code.

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

.. _sphx_glr_gallery_shapes_and_collections_ellipse_demo.py:


============
Ellipse Demo
============

Draw many ellipses. Here individual ellipses are drawn. Compare this
to the :doc:`Ellipse collection example
</gallery/shapes_and_collections/ellipse_collection>`.

.. GENERATED FROM PYTHON SOURCE LINES 10-36

.. code-block:: Python

    import matplotlib.pyplot as plt
    import numpy as np

    from matplotlib.patches import Ellipse

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

    NUM = 250

    ells = [Ellipse(xy=np.random.rand(2) * 10,
                    width=np.random.rand(), height=np.random.rand(),
                    angle=np.random.rand() * 360)
            for i in range(NUM)]

    fig, ax = plt.subplots()
    ax.set(xlim=(0, 10), ylim=(0, 10), aspect="equal")

    for e in ells:
        ax.add_artist(e)
        e.set_clip_box(ax.bbox)
        e.set_alpha(np.random.rand())
        e.set_facecolor(np.random.rand(3))

    plt.show()




.. image-sg:: /gallery/shapes_and_collections/images/sphx_glr_ellipse_demo_001.png
   :alt: ellipse demo
   :srcset: /gallery/shapes_and_collections/images/sphx_glr_ellipse_demo_001.png, /gallery/shapes_and_collections/images/sphx_glr_ellipse_demo_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 37-43

===============
Ellipse Rotated
===============

Draw many ellipses with different angles.


.. GENERATED FROM PYTHON SOURCE LINES 43-56

.. code-block:: Python


    angle_step = 45  # degrees
    angles = np.arange(0, 180, angle_step)

    fig, ax = plt.subplots()
    ax.set(xlim=(-2.2, 2.2), ylim=(-2.2, 2.2), aspect="equal")

    for angle in angles:
        ellipse = Ellipse((0, 0), 4, 2, angle=angle, alpha=0.1)
        ax.add_artist(ellipse)

    plt.show()




.. image-sg:: /gallery/shapes_and_collections/images/sphx_glr_ellipse_demo_002.png
   :alt: ellipse demo
   :srcset: /gallery/shapes_and_collections/images/sphx_glr_ellipse_demo_002.png, /gallery/shapes_and_collections/images/sphx_glr_ellipse_demo_002_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 57-68

.. admonition:: References

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

   - `matplotlib.patches`
   - `matplotlib.patches.Ellipse`
   - `matplotlib.axes.Axes.add_artist`
   - `matplotlib.artist.Artist.set_clip_box`
   - `matplotlib.artist.Artist.set_alpha`
   - `matplotlib.patches.Patch.set_facecolor`


.. _sphx_glr_download_gallery_shapes_and_collections_ellipse_demo.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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