From d791465bbebffbade2f68a0cab1e876bda74dcbb Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Thu, 25 Aug 2022 21:01:59 -0400 Subject: [PATCH] FIX: unbreak ipympl We must not try to make a toolbar for the classes in backend_webaggcore because ipympl inherits from these classes and requires its own toolbar to be used. This also fixes the webagg embedding example without breaking ipympl. closes #23699 --- examples/user_interfaces/embedding_webagg_sgskip.py | 2 +- lib/matplotlib/backends/backend_webagg_core.py | 4 +++- lib/matplotlib/tests/test_backend_webagg.py | 6 ++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/examples/user_interfaces/embedding_webagg_sgskip.py b/examples/user_interfaces/embedding_webagg_sgskip.py index 338303f230bb..dbd6bfb2bcc9 100644 --- a/examples/user_interfaces/embedding_webagg_sgskip.py +++ b/examples/user_interfaces/embedding_webagg_sgskip.py @@ -30,7 +30,7 @@ import matplotlib as mpl -from matplotlib.backends.backend_webagg_core import ( +from matplotlib.backends.backend_webagg import ( FigureManagerWebAgg, new_figure_manager_given_figure) from matplotlib.figure import Figure diff --git a/lib/matplotlib/backends/backend_webagg_core.py b/lib/matplotlib/backends/backend_webagg_core.py index 141dbdcc2e39..ee2d73d0cf95 100644 --- a/lib/matplotlib/backends/backend_webagg_core.py +++ b/lib/matplotlib/backends/backend_webagg_core.py @@ -427,7 +427,9 @@ def set_history_buttons(self): class FigureManagerWebAgg(backend_bases.FigureManagerBase): - _toolbar2_class = ToolbarCls = NavigationToolbar2WebAgg + # This must be None to not break ipympl + _toolbar2_class = None + ToolbarCls = NavigationToolbar2WebAgg def __init__(self, canvas, num): self.web_sockets = set() diff --git a/lib/matplotlib/tests/test_backend_webagg.py b/lib/matplotlib/tests/test_backend_webagg.py index 5c6ddfa258c0..992827863b01 100644 --- a/lib/matplotlib/tests/test_backend_webagg.py +++ b/lib/matplotlib/tests/test_backend_webagg.py @@ -2,6 +2,7 @@ import os import sys import pytest +import matplotlib.backends.backend_webagg_core @pytest.mark.parametrize("backend", ["webagg", "nbagg"]) @@ -25,3 +26,8 @@ def test_webagg_fallback(backend): ret = subprocess.call([sys.executable, "-c", test_code], env=env) assert ret == 0 + + +def test_webagg_core_no_toolbar(): + fm = matplotlib.backends.backend_webagg_core.FigureManagerWebAgg + assert fm._toolbar2_class is None