{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# ggplot style sheet\n\nThis example demonstrates the \"ggplot\" style, which adjusts the style to\nemulate ggplot_ (a popular plotting package for R_).\n\nThese settings were shamelessly stolen from [1]_ (with permission).\n\n.. [1] https://everyhue.me/posts/sane-color-scheme-for-matplotlib/\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\nimport numpy as np\n\nplt.style.use('ggplot')\n\n# Fixing random state for reproducibility\nnp.random.seed(19680801)\n\nfig, axs = plt.subplots(ncols=2, nrows=2)\nax1, ax2, ax3, ax4 = axs.flat\n\n# scatter plot (Note: `plt.scatter` doesn't use default colors)\nx, y = np.random.normal(size=(2, 200))\nax1.plot(x, y, 'o')\n\n# sinusoidal lines with colors from default color cycle\nL = 2*np.pi\nx = np.linspace(0, L)\nncolors = len(plt.rcParams['axes.prop_cycle'])\nshift = np.linspace(0, L, ncolors, endpoint=False)\nfor s in shift:\n ax2.plot(x, np.sin(x + s), '-')\nax2.margins(0)\n\n# bar graphs\nx = np.arange(5)\ny1, y2 = np.random.randint(1, 25, size=(2, 5))\nwidth = 0.25\nax3.bar(x, y1, width)\nax3.bar(x + width, y2, width,\n color=list(plt.rcParams['axes.prop_cycle'])[2]['color'])\nax3.set_xticks(x + width, labels=['a', 'b', 'c', 'd', 'e'])\n\n# circles with colors from default color cycle\nfor i, color in enumerate(plt.rcParams['axes.prop_cycle']):\n xy = np.random.normal(size=2)\n ax4.add_patch(plt.Circle(xy, radius=0.3, color=color['color']))\nax4.axis('equal')\nax4.margins(0)\n\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 }