{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Scatter plot on polar axis\n\nSize increases radially in this example and color increases with angle\n(just to verify the symbols are being scattered correctly).\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\nimport numpy as np\n\n# Fixing random state for reproducibility\nnp.random.seed(19680801)\n\n# Compute areas and colors\nN = 150\nr = 2 * np.random.rand(N)\ntheta = 2 * np.pi * np.random.rand(N)\narea = 200 * r**2\ncolors = theta\n\nfig = plt.figure()\nax = fig.add_subplot(projection='polar')\nc = ax.scatter(theta, r, c=colors, s=area, cmap='hsv', alpha=0.75)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Scatter plot on polar axis, with offset origin\n\nThe main difference with the previous plot is the configuration of the origin\nradius, producing an annulus. Additionally, the theta zero location is set to\nrotate the plot.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "fig = plt.figure()\nax = fig.add_subplot(projection='polar')\nc = ax.scatter(theta, r, c=colors, s=area, cmap='hsv', alpha=0.75)\n\nax.set_rorigin(-2.5)\nax.set_theta_zero_location('W', offset=10)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Scatter plot on polar axis confined to a sector\n\nThe main difference with the previous plots is the configuration of the\ntheta start and end limits, producing a sector instead of a full circle.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "fig = plt.figure()\nax = fig.add_subplot(projection='polar')\nc = ax.scatter(theta, r, c=colors, s=area, cmap='hsv', alpha=0.75)\n\nax.set_thetamin(45)\nax.set_thetamax(135)\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.axes.Axes.scatter` / `matplotlib.pyplot.scatter`\n - `matplotlib.projections.polar`\n - `matplotlib.projections.polar.PolarAxes.set_rorigin`\n - `matplotlib.projections.polar.PolarAxes.set_theta_zero_location`\n - `matplotlib.projections.polar.PolarAxes.set_thetamin`\n - `matplotlib.projections.polar.PolarAxes.set_thetamax`\n\n.. tags::\n\n plot-style: polar\n plot-style: scatter\n level: beginner\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 }