From d80564b28c211f7c3265c639814e924079ec8e1c Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Thu, 3 Nov 2022 21:08:57 +0100 Subject: [PATCH] Backport PR #24354: DOC: clarify rc_context resets all rcParams changes --- lib/matplotlib/__init__.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 77d25bbe3358..70499b77ab07 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -1062,6 +1062,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 @@ -1089,6 +1092,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']