Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 08bb99d

Browse files
committed
Clarify tutorial about style sheets and rcParams
1 parent 3bcc6c9 commit 08bb99d

File tree

3 files changed

+42
-24
lines changed

3 files changed

+42
-24
lines changed

lib/matplotlib/textpath.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def __init__(self, xy, s, size=None, prop=None,
351351
prop : `matplotlib.font_manager.FontProperties`, optional
352352
Font property. If not provided, will use a default
353353
``FontProperties`` with parameters from the
354-
:ref:`rcParams <matplotlib-rcparams>`.
354+
:ref:`rcParams<customizing-with-dynamic-rc-settings>`.
355355
356356
_interpolation_steps : int, optional
357357
(Currently ignored)

tutorials/intermediate/constrainedlayout_guide.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
2323
plt.subplots(constrained_layout=True)
2424
25-
* activate it via :ref:`rcParams<matplotlib-rcparams>`, like::
25+
* activate it via :ref:`rcParams<customizing-with-dynamic-rc-settings>`,
26+
like::
2627
2728
plt.rcParams['figure.constrained_layout.use'] = True
2829
@@ -306,9 +307,9 @@ def example_plot(ax, fontsize=12, hide_labels=False):
306307
# rcParams
307308
# ========
308309
#
309-
# There are five :ref:`rcParams<matplotlib-rcparams>` that can be set,
310-
# either in a script or in the :file:`matplotlibrc` file.
311-
# They all have the prefix ``figure.constrained_layout``:
310+
# There are five :ref:`rcParams<customizing-with-dynamic-rc-settings>`
311+
# that can be set, either in a script or in the :file:`matplotlibrc`
312+
# file. They all have the prefix ``figure.constrained_layout``:
312313
#
313314
# - *use*: Whether to use constrained_layout. Default is False
314315
# - *w_pad*, *h_pad*: Padding around axes objects.

tutorials/introductory/customizing.py

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,43 @@
11
"""
22
.. redirect-from:: /users/customizing
33
4+
=====================================================
45
Customizing Matplotlib with style sheets and rcParams
56
=====================================================
67
78
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:
819
920
Using style sheets
10-
------------------
21+
==================
1122
1223
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
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
1736
There are a number of pre-defined styles :doc:`provided by Matplotlib
1837
</gallery/style_sheets/style_sheets_reference>`. For
1938
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:
2241
"""
2342

2443
import numpy as np
@@ -104,15 +123,10 @@
104123
plt.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

Comments
 (0)