From 52ac741787019e3f6511a5b0af494508e2a73bcc Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Sat, 17 Sep 2022 02:15:05 +0200 Subject: [PATCH] Backport PR #23912: FIX: only expect FigureCanvas on backend module if using new style --- 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 f5c86de1260b..1e94d90d1534 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -263,7 +263,6 @@ def switch_backend(newbackend): backend_mod = importlib.import_module( cbook._backend_module_name(newbackend)) - canvas_class = backend_mod.FigureCanvas required_framework = _get_required_interactive_framework(backend_mod) if required_framework is not None: @@ -293,6 +292,8 @@ class backend_mod(matplotlib.backend_bases._Backend): # also update backend_mod accordingly; also, per-backend customization of # draw_if_interactive is disabled. if new_figure_manager is None: + # only try to get the canvas class if have opted into the new scheme + canvas_class = backend_mod.FigureCanvas def new_figure_manager_given_figure(num, figure): return canvas_class.new_manager(figure, num)