8000 add rc_context to customizing tutorial; fix linestyle example comment · matplotlib/matplotlib@390bf70 · GitHub
[go: up one dir, main page]

Skip to content

Commit 390bf70

Browse files
committed
add rc_context to customizing tutorial; fix linestyle example comment
1 parent c6c85e6 commit 390bf70

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

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