diff --git a/mne/viz/backends/_notebook.py b/mne/viz/backends/_notebook.py index 478d4d0f33b..042a3ca1d0d 100644 --- a/mne/viz/backends/_notebook.py +++ b/mne/viz/backends/_notebook.py @@ -86,7 +86,7 @@ _take_3d_screenshot, # noqa: F401 ) from ._utils import _notebook_vtk_works -from ...utils import check_version +from ...utils import check_version, _soft_import # dict values are icon names from: https://fontawesome.com/icons @@ -1346,10 +1346,9 @@ def _playback_initialize(self, func, timeout, value, rng, time_widget, play_widg class _IpyMplInterface(_AbstractMplInterface): def _mpl_initialize(self): - from matplotlib.backends.backend_nbagg import FigureCanvasNbAgg, FigureManager - - self.canvas = FigureCanvasNbAgg(self.fig) - self.manager = FigureManager(self.canvas, 0) + ipympl = _soft_import("ipympl", "Drawing figures into a notebook.", strict=True) + self.canvas = ipympl.backend_nbagg.Canvas(self.fig) + self.manager = ipympl.backend_nbagg.FigureManager(self.canvas, 0) class _IpyMplCanvas(_AbstractMplCanvas, _IpyMplInterface):