{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Plotting with keywords\n\nSome data structures, like dict, [structured numpy array](https://numpy.org/doc/stable/user/basics.rec.html#structured-arrays)\nor `pandas.DataFrame` provide access to labelled data via string index access\n``data[key]``.\n\nFor these data types, Matplotlib supports passing the whole datastructure via the\n``data`` keyword argument, and using the string names as plot function parameters,\nwhere you'd normally pass in your data.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\nimport numpy as np\n\nnp.random.seed(19680801)\n\ndata = {'a': np.arange(50),\n 'c': np.random.randint(0, 50, 50),\n 'd': np.random.randn(50)}\ndata['b'] = data['a'] + 10 * np.random.randn(50)\ndata['d'] = np.abs(data['d']) * 100\n\nfig, ax = plt.subplots()\nax.scatter('a', 'b', c='c', s='d', data=data)\nax.set(xlabel='entry a', ylabel='entry b')\nplt.show()" ] } ], "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 }