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