1
1
"""
2
2
.. redirect-from:: /users/customizing
3
3
4
+ =====================================================
4
5
Customizing Matplotlib with style sheets and rcParams
5
6
=====================================================
6
7
7
8
Tips 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:
8
16
9
17
Using style sheets
10
- ------------------
18
+ ==================
11
19
12
20
The :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
14
22
<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`.
16
32
17
33
There are a number of pre-defined styles :doc:`provided by Matplotlib
18
34
</gallery/style_sheets/style_sheets_reference>`. For
19
35
example, 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:
22
38
"""
23
39
24
40
import numpy as np
104
120
plt .show ()
105
121
106
122
###############################################################################
107
- # .. _matplotlib-rcparams:
108
- #
109
- # Matplotlib rcParams
110
- # ===================
111
- #
112
123
# .. _customizing-with-dynamic-rc-settings:
113
124
#
114
125
# Dynamic rc settings
115
- # -------------------
126
+ # ===================
116
127
#
117
128
# You can also dynamically change the default rc settings in a python script or
118
129
# interactively from the python shell. All of the rc settings are stored in a
@@ -169,14 +180,13 @@ def plotting_function():
169
180
# .. _customizing-with-matplotlibrc-files:
170
181
#
171
182
# The :file:`matplotlibrc` file
172
- # -----------------------------
183
+ # =============================
173
184
#
174
185
# Matplotlib uses :file:`matplotlibrc` configuration files to customize all
175
186
# kinds of properties, which we call 'rc settings' or 'rc parameters'. You can
176
187
# control the defaults of almost every property in Matplotlib: figure size and
177
188
# 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
180
190
# :file:`matplotlibrc` in four locations, in the following order:
181
191
#
182
192
# 1. :file:`matplotlibrc` in the current working directory, usually used for
@@ -204,8 +214,11 @@ def plotting_function():
204
214
# your customizations to be saved, please move this file to your
205
215
# user-specific matplotlib directory.
206
216
#
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.
209
222
#
210
223
# To display where the currently active :file:`matplotlibrc` file was
211
224
# loaded from, one can do the following::
@@ -214,12 +227,13 @@ def plotting_function():
214
227
# >>> matplotlib.matplotlib_fname()
215
228
# '/home/foo/.config/matplotlib/matplotlibrc'
216
229
#
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.
218
232
#
219
233
# .. _matplotlibrc-sample:
220
234
#
221
235
# A sample matplotlibrc file
222
- # ~~~~~~~~~~~~~~~~~~~~~~~~~~
236
+ # --------------------------
223
237
#
224
238
# .. literalinclude:: ../../../lib/matplotlib/mpl-data/matplotlibrc
225
239
#
0 commit comments