diff --git a/src/plopp/backends/matplotlib/utils.py b/src/plopp/backends/matplotlib/utils.py index 1980771c..00b35787 100644 --- a/src/plopp/backends/matplotlib/utils.py +++ b/src/plopp/backends/matplotlib/utils.py @@ -80,7 +80,7 @@ def make_figure(*args, **kwargs) -> plt.Figure: if is_interactive_backend(): # Create a manager for the figure, which makes it interactive, as well as # making it possible to show the figure from the terminal. - plt._backend_mod.new_figure_manager_given_figure(1, fig) + plt._get_backend_mod().new_figure_manager_given_figure(1, fig) return fig diff --git a/tests/backends/matplotlib/mpl_utils_test.py b/tests/backends/matplotlib/mpl_utils_test.py index 06d4122d..32a8ddb1 100644 --- a/tests/backends/matplotlib/mpl_utils_test.py +++ b/tests/backends/matplotlib/mpl_utils_test.py @@ -2,10 +2,15 @@ # Copyright (c) 2023 Scipp contributors (https://github.com/scipp) import matplotlib +import matplotlib.pyplot as plt import pytest from plopp.backends.matplotlib.figure import StaticFigure -from plopp.backends.matplotlib.utils import is_interactive_backend, is_widget_backend +from plopp.backends.matplotlib.utils import ( + is_interactive_backend, + is_widget_backend, + make_figure, +) from plopp.data.testing import data_array @@ -34,6 +39,15 @@ def test_static_backends_are_neither_interactive_nor_widget(monkeypatch, backend assert not is_widget_backend() +@pytest.mark.usefixtures('_use_ipympl') +def test_make_figure_initializes_pyplot_backend(monkeypatch): + monkeypatch.setattr(plt, '_backend_mod', None) + + fig = make_figure() + + assert fig.canvas.manager is not None + + @pytest.mark.parametrize('backend', ['qtagg', 'tkagg', 'macosx']) def test_gui_backend_makes_static_figure(monkeypatch, backend): # GUI backends are used when plotting from a terminal, where ipywidgets-based