8000 Merge pull request #20505 from rcomer/docs-rcparams-context-manager · matplotlib/matplotlib@4f2f4de · GitHub
[go: up one dir, main page]

Skip to content

Commit 4f2f4de

Browse files
authored
Merge pull request #20505 from rcomer/docs-rcparams-context-manager
Add rc_context to customizing tutorial
2 parents fd8c5d2 + 390bf70 commit 4f2f4de

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed
< 8000 button class="Button Button--iconOnly Button--invisible flex-shrink-0 flex-order-1" aria-label="Collapse file: examples/lines_bars_and_markers/linestyles.py">

examples/lines_bars_and_markers/linestyles.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
linestyle_str = [
2121
('solid', 'solid'), # Same as (0, ()) or '-'
22-
('dotted', 'dotted'), # Same as (0, (1, 1)) or '.'
22+
('dotted', 'dotted'), # Same as (0, (1, 1)) or ':'
2323
('dashed', 'dashed'), # Same as '--'
2424
('dashdot', 'dashdot')] # Same as '-.'
2525

tutorials/introductory/customizing.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,27 @@
138138
mpl.rc('lines', linewidth=4, linestyle='-.')
139139
plt.plot(data)
140140

141+
###############################################################################
142+
# Temporary rc settings
143+
# ---------------------
144+
#
145+
# The :data:`matplotlib.rcParams` object can also be changed temporarily using
146+
# the `matplotlib.rc_context` context manager:
147+
148+
with mpl.rc_context({'lines.linewidth': 2, 'lines.linestyle': ':'}):
149+
plt.plot(data)
150+
151+
###############################################################################
152+
# `matplotlib.rc_context` can also be used as a decorator to modify the
153+
# defaults within a function:
154+
155+
156+
@mpl.rc_context({'lines.linewidth': 3, 'lines.linestyle': '-'})
157+
def plotting_function():
158+
plt.plot(data)
159+
160+
plotting_function()
161+
141162
###############################################################################
142163
# `matplotlib.rcdefaults` will restore the standard Matplotlib
143164
# default settings.

0 commit comments

Comments
 (0)
0