.. only:: html
.. note::
:class: sphx-glr-download-link-note
Click :ref:`here ` to download the full example code
.. rst-class:: sphx-glr-example-title
.. _sphx_glr_gallery_shapes_and_collections_ellipse_collection.py:
==================
Ellipse Collection
==================
Drawing a collection of ellipses. While this would equally be possible using
a `~.collections.EllipseCollection` or `~.collections.PathCollection`, the use
of an `~.collections.EllipseCollection` allows for much shorter code.
.. code-block:: default
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.collections import EllipseCollection
x = np.arange(10)
y = np.arange(15)
X, Y = np.meshgrid(x, y)
XY = np.column_stack((X.ravel(), Y.ravel()))
ww = X / 10.0
hh = Y / 15.0
aa = X * 9
fig, ax = plt.subplots()
ec = EllipseCollection(ww, hh, aa, units='x', offsets=XY,
transOffset=ax.transData)
ec.set_array((X + Y).ravel())
ax.add_collection(ec)
ax.autoscale_view()
ax.set_xlabel('X')
ax.set_ylabel('y')
cbar = plt.colorbar(ec)
cbar.set_label('X+Y')
plt.show()
.. image:: /gallery/shapes_and_collections/images/sphx_glr_ellipse_collection_001.png
:class: sphx-glr-single-img
------------
References
""""""""""
The use of the following functions, methods, classes and modules is shown
in this example:
.. code-block:: default
import matplotlib
matplotlib.collections
matplotlib.collections.EllipseCollection
matplotlib.axes.Axes.add_collection
matplotlib.axes.Axes.autoscale_view
matplotlib.cm.ScalarMappable.set_array
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
.. _sphx_glr_download_gallery_shapes_and_collections_ellipse_collection.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: ellipse_collection.py `
.. container:: sphx-glr-download sphx-glr-download-jupyter
:download:`Download Jupyter notebook: ellipse_collection.ipynb `
.. only:: html
.. rst-class:: sphx-glr-signature
Keywords: matplotlib code example, codex, python plot, pyplot
`Gallery generated by Sphinx-Gallery
`_