{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Ellipse Collection\n\nDrawing a collection of ellipses. While this would equally be possible using\na `~.collections.EllipseCollection` or `~.collections.PathCollection`, the use\nof an `~.collections.EllipseCollection` allows for much shorter code.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\nimport numpy as np\n\nfrom matplotlib.collections import EllipseCollection\n\nx = np.arange(10)\ny = np.arange(15)\nX, Y = np.meshgrid(x, y)\n\nXY = np.column_stack((X.ravel(), Y.ravel()))\n\nww = X / 10.0\nhh = Y / 15.0\naa = X * 9\n\n\nfig, ax = plt.subplots()\n\nec = EllipseCollection(ww, hh, aa, units='x', offsets=XY,\n offset_transform=ax.transData)\nec.set_array((X + Y).ravel())\nax.add_collection(ec)\nax.autoscale_view()\nax.set_xlabel('X')\nax.set_ylabel('y')\ncbar = plt.colorbar(ec)\ncbar.set_label('X+Y')\nplt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ ".. admonition:: References\n\n The use of the following functions, methods, classes and modules is shown\n in this example:\n\n - `matplotlib.collections`\n - `matplotlib.collections.EllipseCollection`\n - `matplotlib.axes.Axes.add_collection`\n - `matplotlib.axes.Axes.autoscale_view`\n - `matplotlib.cm.ScalarMappable.set_array`\n\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.2" } }, "nbformat": 4, "nbformat_minor": 0 }