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

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

.. _sphx_glr_gallery_units_ellipse_with_units.py:


==================
Ellipse with units
==================

Compare the ellipse generated with arcs versus a polygonal approximation.

.. only:: builder_html

   This example requires :download:`basic_units.py <basic_units.py>`

.. GENERATED FROM PYTHON SOURCE LINES 12-39

.. code-block:: Python


    from basic_units import cm

    import matplotlib.pyplot as plt
    import numpy as np

    from matplotlib import patches

    xcenter, ycenter = 0.38*cm, 0.52*cm
    width, height = 1e-1*cm, 3e-1*cm
    angle = -30

    theta = np.deg2rad(np.arange(0.0, 360.0, 1.0))
    x = 0.5 * width * np.cos(theta)
    y = 0.5 * height * np.sin(theta)

    rtheta = np.radians(angle)
    R = np.array([
        [np.cos(rtheta), -np.sin(rtheta)],
        [np.sin(rtheta),  np.cos(rtheta)],
        ])


    x, y = np.dot(R, [x, y])
    x += xcenter
    y += ycenter








.. GENERATED FROM PYTHON SOURCE LINES 40-60

.. code-block:: Python


    fig = plt.figure()
    ax = fig.add_subplot(211, aspect='auto')
    ax.fill(x, y, alpha=0.2, facecolor='yellow',
            edgecolor='yellow', linewidth=1, zorder=1)

    e1 = patches.Ellipse((xcenter, ycenter), width, height,
                         angle=angle, linewidth=2, fill=False, zorder=2)

    ax.add_patch(e1)

    ax = fig.add_subplot(212, aspect='equal')
    ax.fill(x, y, alpha=0.2, facecolor='green', edgecolor='green', zorder=1)
    e2 = patches.Ellipse((xcenter, ycenter), width, height,
                         angle=angle, linewidth=2, fill=False, zorder=2)


    ax.add_patch(e2)
    fig.savefig('ellipse_compare')




.. image-sg:: /gallery/units/images/sphx_glr_ellipse_with_units_001.png
   :alt: ellipse with units
   :srcset: /gallery/units/images/sphx_glr_ellipse_with_units_001.png, /gallery/units/images/sphx_glr_ellipse_with_units_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 61-82

.. code-block:: Python


    fig = plt.figure()
    ax = fig.add_subplot(211, aspect='auto')
    ax.fill(x, y, alpha=0.2, facecolor='yellow',
            edgecolor='yellow', linewidth=1, zorder=1)

    e1 = patches.Arc((xcenter, ycenter), width, height,
                     angle=angle, linewidth=2, fill=False, zorder=2)

    ax.add_patch(e1)

    ax = fig.add_subplot(212, aspect='equal')
    ax.fill(x, y, alpha=0.2, facecolor='green', edgecolor='green', zorder=1)
    e2 = patches.Arc((xcenter, ycenter), width, height,
                     angle=angle, linewidth=2, fill=False, zorder=2)


    ax.add_patch(e2)
    fig.savefig('arc_compare')

    plt.show()



.. image-sg:: /gallery/units/images/sphx_glr_ellipse_with_units_002.png
   :alt: ellipse with units
   :srcset: /gallery/units/images/sphx_glr_ellipse_with_units_002.png, /gallery/units/images/sphx_glr_ellipse_with_units_002_2_00x.png 2.00x
   :class: sphx-glr-single-img






.. _sphx_glr_download_gallery_units_ellipse_with_units.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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