@@ -274,13 +274,11 @@ def switch_backend(newbackend):
274
274
"framework, as {!r} is currently running" .format (
275
275
newbackend , required_framework , current_framework ))
276
276
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.
279
278
280
279
# Classically, backends can directly export these functions. This should
281
280
# keep working for backcompat.
282
281
new_figure_manager = getattr (backend_mod , "new_figure_manager" , None )
283
- # draw_if_interactive = getattr(backend_mod, "draw_if_interactive", None)
284
282
# show = getattr(backend_mod, "show", None)
285
283
# In that classical approach, backends are implemented as modules, but
286
284
# "inherit" default method implementations from backend_bases._Backend.
@@ -290,8 +288,9 @@ class backend_mod(matplotlib.backend_bases._Backend):
290
288
locals ().update (vars (backend_mod ))
291
289
292
290
# 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.
295
294
if new_figure_manager is None :
296
295
def new_figure_manager_given_figure (num , figure ):
297
296
return canvas_class .new_manager (figure , num )
@@ -300,9 +299,16 @@ def new_figure_manager(num, *args, FigureClass=Figure, **kwargs):
300
299
fig = FigureClass (* args , ** kwargs )
301
300
return new_figure_manager_given_figure (num , fig )
302
301
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
+
303
308
backend_mod .new_figure_manager_given_figure = \
304
309
new_figure_manager_given_figure
305
310
backend_mod .new_figure_manager = new_figure_manager
311
+ backend_mod .draw_if_interactive = draw_if_interactive
306
312
307
313
_log .debug ("Loaded backend %s version %s." ,
308
314
newbackend , backend_mod .backend_version )
@@ -762,9 +768,9 @@ def figure(num=None, # autoincrement if None, else integer from 1-N
762
768
763
769
Notes
764
770
-----
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.
768
774
769
775
If you are creating many figures, make sure you explicitly call
770
776
`.pyplot.close` on the figures you are not using, because this will
0 commit comments