11"""
22.. redirect-from:: /users/customizing
33
4+ =====================================================
45Customizing Matplotlib with style sheets and rcParams
56=====================================================
67
78Tips for customizing the properties and default styles of Matplotlib.
9+ There are basically three ways to customize Matplotlib:
10+
11+ 1. :ref:`Using style sheets<customizing-with-style-sheets>`.
12+ 2. :ref:`Setting rcParams at runtime<customizing-with-dynamic-rc-settings>`.
13+ 3. :ref:`Changing your matplotlibrc file<customizing-with-matplotlibrc-files>`.
14+
15+ .. _customizing-with-style-sheets:
816
917Using style sheets
10- ------------------
18+ ==================
1119
1220The :mod:`.style` package adds support for easy-to-switch plotting
13- "styles" with the same parameters as a :ref:`matplotlib rc
21+ "styles" with the same parameters (rcParams) as a :ref:`matplotlibrc
1422<customizing-with-matplotlibrc-files>` file (which is read at startup to
15- configure Matplotlib).
23+ configure Matplotlib). However, in a style sheet you can only set
24+ rcParams that are related to the actual style of a plot. Other rcParams,
25+ like *backend*, will be ignored. This behavior is different fom the
26+ :file:`matplotlibrc` file, which supports all rcParams. In this way,
27+ style sheets are portable between different machines without having to
28+ worry about dependencies which might or might not be installed on
29+ another machine. For a full list of rcParams see `matplotlib.rcParams`.
30+ For a list of rcParams that are ignored in style sheets see
31+ `matplotlib.style.use`.
1632
1733There are a number of pre-defined styles :doc:`provided by Matplotlib
1834</gallery/style_sheets/style_sheets_reference>`. For
1935example, there's a pre-defined style called "ggplot", which emulates the
20- aesthetics of ggplot_ (a popular plotting package for R_). To use this style,
21- just add:
36+ aesthetics of ggplot_ (a popular plotting package for R_). To use this
37+ style, just add:
2238"""
2339
2440import numpy as np
104120plt .show ()
105121
106122###############################################################################
107- # .. _matplotlib-rcparams:
108- #
109- # Matplotlib rcParams
110- # ===================
111- #
112123# .. _customizing-with-dynamic-rc-settings:
113124#
114125# Dynamic rc settings
115- # -------------------
126+ # ===================
116127#
117128# You can also dynamically change the default rc settings in a python script or
118129# interactively from the python shell. All of the rc settings are stored in a
@@ -169,14 +180,13 @@ def plotting_function():
169180# .. _customizing-with-matplotlibrc-files:
170181#
171182# The :file:`matplotlibrc` file
172- # -----------------------------
183+ # =============================
173184#
174185# Matplotlib uses :file:`matplotlibrc` configuration files to customize all
175186# kinds of properties, which we call 'rc settings' or 'rc parameters'. You can
176187# control the defaults of almost every property in Matplotlib: figure size and
177188# DPI, line width, color and style, axes, axis and grid properties, text and
178- # font properties and so on. When a URL or path is not specified with a call to
179- # ``style.use('<path>/<style-name>.mplstyle')``, Matplotlib looks for
189+ # font properties and so on. Matplotlib looks for
180190# :file:`matplotlibrc` in four locations, in the following order:
181191#
182192# 1. :file:`matplotlibrc` in the current working directory, usually used for
@@ -204,8 +214,11 @@ def plotting_function():
204214# your customizations to be saved, please move this file to your
205215# user-specific matplotlib directory.
206216#
207- # Once a :file:`matplotlibrc` file has been found, it will *not* search any of
208- # the other paths.
217+ # Once a :file:`matplotlibrc` file has been found, it will *not* search
218+ # any of the other paths. When a
219+ # :ref:`style sheet<customizing-with-style-sheets>` is given with
220+ # ``style.use('<path>/<style-name>.mplstyle')``, settings specified in
221+ # the style sheet take precedence over the :file:`matplotlibrc` file.
209222#
210223# To display where the currently active :file:`matplotlibrc` file was
211224# loaded from, one can do the following::
@@ -214,12 +227,13 @@ def plotting_function():
214227# >>> matplotlib.matplotlib_fname()
215228# '/home/foo/.config/matplotlib/matplotlibrc'
216229#
217- # See below for a sample :ref:`matplotlibrc file<matplotlibrc-sample>`.
230+ # See below for a sample :ref:`matplotlibrc file<matplotlibrc-sample>`
231+ # and see `matplotlib.rcParams` for a full list of configurable rcParams.
218232#
219233# .. _matplotlibrc-sample:
220234#
221235# A sample matplotlibrc file
222- # ~~~~~~~~~~~~~~~~~~~~~~~~~~
236+ # --------------------------
223237#
224238# .. literalinclude:: ../../../lib/matplotlib/mpl-data/matplotlibrc
225239#
0 commit comments