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 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+ Style sheets take precedence over :file:`matplotlibrc` files and setting
16+ rcParams at runtime takes precedence over style sheets.
17+
18+ .. _customizing-with-style-sheets:
819
920Using style sheets
10- ------------------
21+ ==================
1122
1223The :mod:`.style` package adds support for easy-to-switch plotting
13- "styles" with the same parameters as a :ref:`matplotlib rc
24+ "styles" with the same parameters (rcParams) as a :ref:`matplotlibrc
1425<customizing-with-matplotlibrc-files>` file (which is read at startup to
15- configure Matplotlib).
26+ configure Matplotlib). However, in a style sheet you can only set
27+ rcParams that are related to the actual style of a plot. Other rcParams,
28+ like *backend*, will be ignored. This behavior is different fom the
29+ :file:`matplotlibrc` file, which supports all rcParams. In this way,
30+ style sheets are portable between different machines without having to
31+ worry about dependencies which might or might not be installed on
32+ another machine. For a full list of rcParams see `matplotlib.rcParams`.
33+ For a list of rcParams that are ignored in style sheets see
34+ `matplotlib.style.use`.
1635
1736There are a number of pre-defined styles :doc:`provided by Matplotlib
1837</gallery/style_sheets/style_sheets_reference>`. For
1938example, 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:
39+ aesthetics of ggplot_ (a popular plotting package for R_). To use this
40+ style, add:
2241"""
2342
2443import numpy as np
104123plt .show ()
105124
106125###############################################################################
107- # .. _matplotlib-rcparams:
108- #
109- # Matplotlib rcParams
110- # ===================
111- #
112126# .. _customizing-with-dynamic-rc-settings:
113127#
114128# Dynamic rc settings
115- # -------------------
129+ # ===================
116130#
117131# You can also dynamically change the default rc settings in a python script or
118132# interactively from the python shell. All of the rc settings are stored in a
@@ -169,14 +183,13 @@ def plotting_function():
169183# .. _customizing-with-matplotlibrc-files:
170184#
171185# The :file:`matplotlibrc` file
172- # -----------------------------
186+ # =============================
173187#
174188# Matplotlib uses :file:`matplotlibrc` configuration files to customize all
175189# kinds of properties, which we call 'rc settings' or 'rc parameters'. You can
176190# control the defaults of almost every property in Matplotlib: figure size and
177191# 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
192+ # font properties and so on. Matplotlib looks for
180193# :file:`matplotlibrc` in four locations, in the following order:
181194#
182195# 1. :file:`matplotlibrc` in the current working directory, usually used for
@@ -204,8 +217,11 @@ def plotting_function():
204217# your customizations to be saved, please move this file to your
205218# user-specific matplotlib directory.
206219#
207- # Once a :file:`matplotlibrc` file has been found, it will *not* search any of
208- # the other paths.
220+ # Once a :file:`matplotlibrc` file has been found, it will *not* search
221+ # any of the other paths. When a
222+ # :ref:`style sheet<customizing-with-style-sheets>` is given with
223+ # ``style.use('<path>/<style-name>.mplstyle')``, settings specified in
224+ # the style sheet take precedence over the :file:`matplotlibrc` file.
209225#
210226# To display where the currently active :file:`matplotlibrc` file was
211227# loaded from, one can do the following::
@@ -214,12 +230,13 @@ def plotting_function():
214230# >>> matplotlib.matplotlib_fname()
215231# '/home/foo/.config/matplotlib/matplotlibrc'
216232#
217- # See below for a sample :ref:`matplotlibrc file<matplotlibrc-sample>`.
233+ # See below for a sample :ref:`matplotlibrc file<matplotlibrc-sample>`
234+ # and see `matplotlib.rcParams` for a full list of configurable rcParams.
218235#
219236# .. _matplotlibrc-sample:
220237#
221- # A sample matplotlibrc file
222- # ~~~~~~~~~~~~~~~~~~~~~~~~~~
238+ # The default :file:` matplotlibrc` file
239+ # -------------------------------------
223240#
224241# .. literalinclude:: ../../../lib/matplotlib/mpl-data/matplotlibrc
225242#
0 commit comments