{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Mapping marker properties to multivariate data\n\nThis example shows how to use different properties of markers to plot\nmultivariate datasets. Here we represent a successful baseball throw as a\nsmiley face with marker size mapped to the skill of thrower, marker rotation to\nthe take-off angle, and thrust to the marker color.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\nimport numpy as np\n\nfrom matplotlib.colors import Normalize\nfrom matplotlib.markers import MarkerStyle\nfrom matplotlib.text import TextPath\nfrom matplotlib.transforms import Affine2D\n\nSUCCESS_SYMBOLS = [\n TextPath((0, 0), \"\u2639\"),\n TextPath((0, 0), \"\ud83d\ude12\"),\n TextPath((0, 0), \"\u263a\"),\n]\n\nN = 25\nnp.random.seed(42)\nskills = np.random.uniform(5, 80, size=N) * 0.1 + 5\ntakeoff_angles = np.random.normal(0, 90, N)\nthrusts = np.random.uniform(size=N)\nsuccessful = np.random.randint(0, 3, size=N)\npositions = np.random.normal(size=(N, 2)) * 5\ndata = zip(skills, takeoff_angles, thrusts, successful, positions)\n\ncmap = plt.colormaps[\"plasma\"]\nfig, ax = plt.subplots()\nfig.suptitle(\"Throwing success\", size=14)\nfor skill, takeoff, thrust, mood, pos in data:\n t = Affine2D().scale(skill).rotate_deg(takeoff)\n m = MarkerStyle(SUCCESS_SYMBOLS[mood], transform=t)\n ax.plot(pos[0], pos[1], marker=m, color=cmap(thrust))\nfig.colorbar(plt.cm.ScalarMappable(norm=Normalize(0, 1), cmap=cmap),\n ax=ax, label=\"Normalized Thrust [a.u.]\")\nax.set_xlabel(\"X position [m]\")\nax.set_ylabel(\"Y position [m]\")\n\nplt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ ".. tags::\n\n component: marker\n styling: color,\n styling: shape\n level: beginner\n purpose: fun\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 }