@@ -274,13 +274,11 @@ def switch_backend(newbackend):
274274 "framework, as {!r} is currently running" .format (
275275 newbackend , required_framework , current_framework ))
276276
277- # Load the new_figure_manager(), draw_if_interactive(), and show()
278- # functions from the backend.
277+ # Load the new_figure_manager() and show() functions from the backend.
279278
280279 # Classically, backends can directly export these functions. This should
281280 # keep working for backcompat.
282281 new_figure_manager = getattr (backend_mod , "new_figure_manager" , None )
283- # draw_if_interactive = getattr(backend_mod, "draw_if_interactive", None)
284282 # show = getattr(backend_mod, "show", None)
285283 # In that classical approach, backends are implemented as modules, but
286284 # "inherit" default method implementations from backend_bases._Backend.
@@ -290,8 +288,9 @@ class backend_mod(matplotlib.backend_bases._Backend):
290288 locals ().update (vars (backend_mod ))
291289
292290 # However, the newer approach for defining new_figure_manager (and, in
293- # the future, draw_if_interactive and show) is to derive them from canvas
294- # methods. In that case, also update backend_mod accordingly.
291+ # the future, show) is to derive them from canvas methods. In that case,
292+ # also update backend_mod accordingly; also, per-backend customization of
293+ # draw_if_interactive is disabled.
295294 if new_figure_manager is None :
296295 def new_figure_manager_given_figure (num , figure ):
297296 return canvas_class .new_manager (figure , num )
@@ -300,9 +299,16 @@ def new_figure_manager(num, *args, FigureClass=Figure, **kwargs):
300299 fig = FigureClass (* args , ** kwargs )
301300 return new_figure_manager_given_figure (num , fig )
302301
302+ def draw_if_interactive ():
303+ if matplotlib .is_interactive ():
304+ manager = _pylab_helpers .Gcf .get_active ()
305+ if manager :
306+ manager .canvas .draw_idle ()
307+
303308 backend_mod .new_figure_manager_given_figure = \
304309 new_figure_manager_given_figure
305310 backend_mod .new_figure_manager = new_figure_manager
311+ backend_mod .draw_if_interactive = draw_if_interactive
306312
307313 _log .debug ("Loaded backend %s version %s." ,
308314 newbackend , backend_mod .backend_version )
@@ -762,9 +768,9 @@ def figure(num=None, # autoincrement if None, else integer from 1-N
762768
763769 Notes
764770 -----
765- Newly created figures will be passed to the
766- `~.backend_template. new_figure_manager` function provided by the current
767- backend, which will install a canvas and a manager on the figure.
771+ Newly created figures are passed to the `~.FigureCanvasBase.new_manager`
772+ method or the ` new_figure_manager` function provided by the current
773+ backend, which install a canvas and a manager on the figure.
768774
769775 If you are creating many figures, make sure you explicitly call
770776 `.pyplot.close` on the figures you are not using, because this will
0 commit comments