{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Ellipse Demo\n\nDraw many ellipses. Here individual ellipses are drawn. Compare this\nto the :doc:`Ellipse collection example\n`.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\nimport numpy as np\n\nfrom matplotlib.patches import Ellipse\n\n# Fixing random state for reproducibility\nnp.random.seed(19680801)\n\nNUM = 250\n\nells = [Ellipse(xy=np.random.rand(2) * 10,\n width=np.random.rand(), height=np.random.rand(),\n angle=np.random.rand() * 360)\n for i in range(NUM)]\n\nfig, ax = plt.subplots()\nax.set(xlim=(0, 10), ylim=(0, 10), aspect=\"equal\")\n\nfor e in ells:\n ax.add_artist(e)\n e.set_clip_box(ax.bbox)\n e.set_alpha(np.random.rand())\n e.set_facecolor(np.random.rand(3))\n\nplt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Ellipse Rotated\n\nDraw many ellipses with different angles.\n\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "angle_step = 45 # degrees\nangles = np.arange(0, 180, angle_step)\n\nfig, ax = plt.subplots()\nax.set(xlim=(-2.2, 2.2), ylim=(-2.2, 2.2), aspect=\"equal\")\n\nfor angle in angles:\n ellipse = Ellipse((0, 0), 4, 2, angle=angle, alpha=0.1)\n ax.add_artist(ellipse)\n\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.patches`\n - `matplotlib.patches.Ellipse`\n - `matplotlib.axes.Axes.add_artist`\n - `matplotlib.artist.Artist.set_clip_box`\n - `matplotlib.artist.Artist.set_alpha`\n - `matplotlib.patches.Patch.set_facecolor`\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 }