From 724387e5d7d0e95d1b44e825a16f05345332b0e9 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Thu, 3 Nov 2022 14:28:33 -0400 Subject: [PATCH] DOC: clarify rc_context resets all rcParams changes Inspired by #24351 --- lib/matplotlib/__init__.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 569cf59977aa..7fb65f08b3b8 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -1080,6 +1080,9 @@ def rc_context(rc=None, fname=None): The :rc:`backend` will not be reset by the context manager. + rcParams changed both through the context manager invocation and + in the body of the context will be reset on context exit. + Parameters ---------- rc : dict @@ -1107,6 +1110,13 @@ def rc_context(rc=None, fname=None): with mpl.rc_context(fname='print.rc'): plt.plot(x, y) # uses 'print.rc' + Setting in the context body:: + + with mpl.rc_context(): + # will be reset + mpl.rcParams['lines.linewidth'] = 5 + plt.plot(x, y) + """ orig = dict(rcParams.copy()) del orig['backend']