From 33996717c45c27358d1c00ef6b4408d34ee498cf Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Wed, 22 Jul 2020 14:56:28 -0400 Subject: [PATCH] FIX: Be sure matplotlib.backends is imported before we use it If the user specifies the backend via `'module://XZY'` there in no guarantee that they have imported `matplotilb.backends` (which is an empty `__init__.py`) as part of their module which results in an AttributeError when we monkeypatch the backend name into it. closes #18022 --- lib/matplotlib/pyplot.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index fba7f1a7b323..8ae8bba82593 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -227,7 +227,8 @@ def switch_backend(newbackend): The name of the backend to use. """ global _backend_mod - + # make sure the init is pulled up so we can assign to it later + import matplotlib.backends close("all") if newbackend is rcsetup._auto_backend_sentinel: