Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c42e922

Browse filesBrowse files
authored
Merge pull request #17162 from timhoffm/doc-rc-context
Update docs of rc_context()
2 parents 91ad867 + 4f42777 commit c42e922
Copy full SHA for c42e922

File tree

Expand file treeCollapse file tree

5 files changed

+29
-23
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+29
-23
lines changed

‎lib/matplotlib/__init__.py

Copy file name to clipboardExpand all lines: lib/matplotlib/__init__.py
+24-18Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ def rc_params_from_file(fname, fail_on_error=False, use_default_template=True):
842842
Parameters
843843
----------
844844
fname : str or path-like
845-
Name of file parsed for Matplotlib settings.
845+
A file with Matplotlib rc settings.
846846
fail_on_error : bool
847847
If True, raise an error when the parser fails to convert a parameter.
848848
use_default_template : bool
@@ -1019,8 +1019,8 @@ def rc_file(fname, *, use_default_template=True):
10191019
10201020
Parameters
10211021
----------
1022-
fname : str
1023-
Name of file parsed for matplotlib settings.
1022+
fname : str or path-like
1023+
A file with Matplotlib rc settings.
10241024
10251025
use_default_template : bool
10261026
If True, initialize with default parameters before updating with those
@@ -1040,29 +1040,35 @@ def rc_file(fname, *, use_default_template=True):
10401040
@contextlib.contextmanager
10411041
def rc_context(rc=None, fname=None):
10421042
"""
1043-
Return a context manager for managing rc settings.
1044-
1045-
This allows one to do::
1043+
Return a context manager for temporarily changing rcParams.
10461044
1047-
with mpl.rc_context(fname='screen.rc'):
1048-
plt.plot(x, a) # uses 'screen.rc'
1049-
with mpl.rc_context(fname='print.rc'):
1050-
plt.plot(x, b) # uses 'print.rc'
1051-
plt.plot(x, c) # uses 'screen.rc'
1052-
1053-
A dictionary can also be passed to the context manager::
1045+
Parameters
1046+
----------
1047+
rc : dict
1048+
The rcParams to temporarily set.
1049+
fname : str or path-like
1050+
A file with Matplotlib rc settings. If both *fname* and *rc* are given,
1051+
settings from *rc* take precedence.
10541052
1055-
with mpl.rc_context(rc={'text.usetex': True}, fname='screen.rc'):
1056-
plt.plot(x, a)
1053+
See Also
1054+
--------
1055+
:ref:`customizing-with-matplotlibrc-files`
10571056
1058-
The *rc* dictionary takes precedence over the settings loaded from *fname*.
1059-
Passing a dictionary only is also valid. For example, a common usage is::
1057+
Examples
1058+
--------
1059+
Passing explicit values via a dict::
10601060
10611061
with mpl.rc_context({'interactive': False}):
10621062
fig, ax = plt.subplots()
10631063
ax.plot(range(3), range(3))
1064-
fig.savefig('A.png', format='png')
1064+
fig.savefig('example.png')
10651065
plt.close(fig)
1066+
1067+
Loading settings from a file::
1068+
1069+
with mpl.rc_context(fname='print.rc'):
1070+
plt.plot(x, y) # uses 'print.rc'
1071+
10661072
"""
10671073
orig = rcParams.copy()
10681074
try:

‎lib/matplotlib/backends/backend_agg.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_agg.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ def print_png(self, filename_or_obj, *args,
439439
440440
Parameters
441441
----------
442-
filename_or_obj : str or PathLike or file-like object
442+
filename_or_obj : str or path-like or file-like
443443
The file to write to.
444444
445445
metadata : dict, optional
@@ -526,7 +526,7 @@ def print_jpg(self, filename_or_obj, *args, dryrun=False, pil_kwargs=None,
526526
527527
Parameters
528528
----------
529-
filename_or_obj : str or PathLike or file-like object
529+
filename_or_obj : str or path-like or file-like
530530
The file to write to.
531531
532532
Other Parameters

‎lib/matplotlib/cbook/__init__.py

Copy file name to clipboardExpand all lines: lib/matplotlib/cbook/__init__.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ def to_filehandle(fname, flag='r', return_opened=False, encoding=None):
378378
379379
Parameters
380380
----------
381-
fname : str or path-like or file-like object
381+
fname : str or path-like or file-like
382382
If `str` or `os.PathLike`, the file is opened using the flags specified
383383
by *flag* and *encoding*. If a file-like object, it is passed through.
384384
flag : str, default 'r'

‎lib/matplotlib/figure.py

Copy file name to clipboardExpand all lines: lib/matplotlib/figure.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2049,7 +2049,7 @@ def savefig(self, fname, *, transparent=None, **kwargs):
20492049
20502050
Parameters
20512051
----------
2052-
fname : str or PathLike or file-like object
2052+
fname : str or path-like or file-like
20532053
A path, or a Python file-like object, or
20542054
possibly some backend-dependent object such as
20552055
`matplotlib.backends.backend_pdf.PdfPages`.

‎lib/matplotlib/image.py

Copy file name to clipboardExpand all lines: lib/matplotlib/image.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1475,7 +1475,7 @@ def imsave(fname, arr, vmin=None, vmax=None, cmap=None, format=None,
14751475
14761476
Parameters
14771477
----------
1478-
fname : str or PathLike or file-like
1478+
fname : str or path-like or file-like
14791479
A path or a file-like object to store the image in.
14801480
If *format* is not set, then the output format is inferred from the
14811481
extension of *fname*, if any, and from :rc:`savefig.format` otherwise.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.