diff --git a/doc/api/matplotlib_configuration_api.rst b/doc/api/matplotlib_configuration_api.rst index 9f0ad3678ffb..26ce3ac57edf 100644 --- a/doc/api/matplotlib_configuration_api.rst +++ b/doc/api/matplotlib_configuration_api.rst @@ -12,21 +12,15 @@ The top level :mod:`matplotlib` module An instance of :class:`RcParams` for handling default matplotlib values. -.. autofunction:: rc - -.. autofunction::rcdefaults - -.. autofunction::rc_file +.. autofunction:: rc_context -.. autofunction::rc_context - -.. autofunction:: matplotlib_fname +.. autofunction:: rc -.. autofunction::rc_file_defaults +.. autofunction:: rc_file -.. autofunction::interactive +.. autofunction:: rcdefaults -.. autofunction::is_interactive +.. autofunction:: rc_file_defaults .. autoclass:: RcParams @@ -34,4 +28,8 @@ The top level :mod:`matplotlib` module .. autofunction:: rc_params_from_file -.. autoclass:: rc_context +.. autofunction:: matplotlib_fname + +.. autofunction:: interactive + +.. autofunction:: is_interactive diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 187501efcefb..daf8e315f7cf 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -103,21 +103,22 @@ unicode_literals) import six -import sys -import distutils.version -from itertools import chain from collections import MutableMapping +import contextlib +import distutils.version +import distutils.sysconfig +import functools import io import inspect +import itertools import locale import os import re +import sys import tempfile import warnings -import contextlib -import distutils.sysconfig -import functools + # cbook must import matplotlib only within function # definitions, so it is safe to import from it here. from . import cbook @@ -798,9 +799,8 @@ def gen_candidates(): # The following may use a value of None to suppress the warning. _deprecated_set = {'axes.hold'} # do NOT include in _all_deprecated -_all_deprecated = set(chain(_deprecated_ignore_map, - _deprecated_map, - _obsolete_set)) +_all_deprecated = set(itertools.chain( + _deprecated_ignore_map, _deprecated_map, _obsolete_set)) class RcParams(MutableMapping, dict): @@ -1223,7 +1223,8 @@ def rc_file(fname): rcParams.update(rc_params_from_file(fname)) -class rc_context(object): +@contextlib.contextmanager +def rc_context(rc=None, fname=None): """ Return a context manager for managing rc settings. @@ -1256,26 +1257,16 @@ class rc_context(object): """ - def __init__(self, rc=None, fname=None): - self.rcdict = rc - self.fname = fname - self._rcparams = rcParams.copy() - try: - if self.fname: - rc_file(self.fname) - if self.rcdict: - rcParams.update(self.rcdict) - except: - # if anything goes wrong, revert rc parameters and re-raise - rcParams.clear() - rcParams.update(self._rcparams) - raise - - def __enter__(self): - return self - - def __exit__(self, type, value, tb): - rcParams.update(self._rcparams) + orig = rcParams.copy() + try: + if fname: + rc_file(fname) + if rc: + rcParams.update(rc) + yield + finally: + # No need to revalidate the original values. + dict.update(rcParams, orig) _use_error_msg = """ pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy