{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Colors in the default property cycle\n\nDisplay the colors from the default prop_cycle, which is obtained from the\n`rc parameters`.\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 TABLEAU_COLORS, same_color\n\n\ndef f(x, a):\n \"\"\"A nice sigmoid-like parametrized curve, ending approximately at *a*.\"\"\"\n return 0.85 * a * (1 / (1 + np.exp(-x)) + 0.2)\n\n\nfig, ax = plt.subplots()\nax.axis('off')\nax.set_title(\"Colors in the default property cycle\")\n\nprop_cycle = plt.rcParams['axes.prop_cycle']\ncolors = prop_cycle.by_key()['color']\nx = np.linspace(-4, 4, 200)\n\nfor i, (color, color_name) in enumerate(zip(colors, TABLEAU_COLORS)):\n assert same_color(color, color_name)\n pos = 4.5 - i\n ax.plot(x, f(x, pos))\n ax.text(4.2, pos, f\"'C{i}': '{color_name}'\", color=color, va=\"center\")\n ax.bar(9, 1, width=1.5, bottom=pos-0.5)\n\nplt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ ".. admonition:: References\n\n The use of the following functions, methods, classes and modules is shown\n in this example:\n\n - `matplotlib.axes.Axes.axis`\n - `matplotlib.axes.Axes.text`\n - `matplotlib.colors.same_color`\n - `cycler.Cycler`\n\n.. tags::\n\n styling: color\n purpose: reference\n plot-type: line\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.5" } }, "nbformat": 4, "nbformat_minor": 0 }