{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Grayscale style sheet\n\nThis example demonstrates the \"grayscale\" style sheet, which changes all colors\nthat are defined as `.rcParams` to grayscale. Note, however, that not all\nplot elements respect `.rcParams`.\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\ndef color_cycle_example(ax):\n L = 6\n x = np.linspace(0, L)\n ncolors = len(plt.rcParams['axes.prop_cycle'])\n shift = np.linspace(0, L, ncolors, endpoint=False)\n for s in shift:\n ax.plot(x, np.sin(x + s), 'o-')\n\n\ndef image_and_patch_example(ax):\n ax.imshow(np.random.random(size=(20, 20)), interpolation='none')\n c = plt.Circle((5, 5), radius=5, label='patch')\n ax.add_patch(c)\n\n\nplt.style.use('grayscale')\n\nfig, (ax1, ax2) = plt.subplots(ncols=2)\nfig.suptitle(\"'grayscale' style sheet\")\n\ncolor_cycle_example(ax1)\nimage_and_patch_example(ax2)\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 }