diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index af6fe7babc50..20b918407047 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -344,8 +344,12 @@ def __init__(self, # use it, for some reason. def _repr_html_(self): - from matplotlib.backends import backend_webagg - return backend_webagg.ipython_inline_display(self) + # We can't use "isinstance" here, because then we'd end up importing + # webagg unconditiionally. + if (self.canvas is not None and + 'WebAgg' in self.canvas.__class__.__name__): + from matplotlib.backends import backend_webagg + return backend_webagg.ipython_inline_display(self) def show(self, warn=True): """