{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Scatter plot with masked values\n\nMask some data points and add a line demarking\nmasked regions.\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\nN = 100\nr0 = 0.6\nx = 0.9 * np.random.rand(N)\ny = 0.9 * np.random.rand(N)\narea = (20 * np.random.rand(N))**2 # 0 to 10 point radii\nc = np.sqrt(area)\nr = np.sqrt(x ** 2 + y ** 2)\narea1 = np.ma.masked_where(r < r0, area)\narea2 = np.ma.masked_where(r >= r0, area)\nplt.scatter(x, y, s=area1, marker='^', c=c)\nplt.scatter(x, y, s=area2, marker='o', c=c)\n# Show the boundary between the regions:\ntheta = np.arange(0, np.pi / 2, 0.01)\nplt.plot(r0 * np.cos(theta), r0 * np.sin(theta))\n\nplt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ ".. tags::\n\n component: marker\n plot-type: 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 }