{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Customize Rc\n\nI'm not trying to make a good-looking figure here, but just to show\nsome examples of customizing `.rcParams` on the fly.\n\nIf you like to work interactively, and need to create different sets\nof defaults for figures (e.g., one set of defaults for publication, one\nset for interactive exploration), you may want to define some\nfunctions in a custom module that set the defaults, e.g.,::\n\n def set_pub():\n rcParams.update({\n \"font.weight\": \"bold\", # bold fonts\n \"tick.labelsize\": 15, # large tick labels\n \"lines.linewidth\": 1, # thick lines\n \"lines.color\": \"k\", # black lines\n \"grid.color\": \"0.5\", # gray gridlines\n \"grid.linestyle\": \"-\", # solid gridlines\n \"grid.linewidth\": 0.5, # thin gridlines\n \"savefig.dpi\": 300, # higher resolution output.\n })\n\nThen as you are working interactively, you just need to do::\n\n >>> set_pub()\n >>> plot([1, 2, 3])\n >>> savefig('myfig')\n >>> rcdefaults() # restore the defaults\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n\nplt.subplot(311)\nplt.plot([1, 2, 3])\n\n# the axes attributes need to be set before the call to subplot\nplt.rcParams.update({\n \"font.weight\": \"bold\",\n \"xtick.major.size\": 5,\n \"xtick.major.pad\": 7,\n \"xtick.labelsize\": 15,\n \"grid.color\": \"0.5\",\n \"grid.linestyle\": \"-\",\n \"grid.linewidth\": 5,\n \"lines.linewidth\": 2,\n \"lines.color\": \"g\",\n})\nplt.subplot(312)\nplt.plot([1, 2, 3])\nplt.grid(True)\n\nplt.rcdefaults()\nplt.subplot(313)\nplt.plot([1, 2, 3])\nplt.grid(True)\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 }