@@ -495,6 +495,21 @@ def destroy(event):
495
495
Gcf .destroy (manager )
496
496
497
497
cid = canvas .mpl_connect ('close_event' , destroy )
498
+
499
+ # Only register figure for showing when in interactive mode (otherwise
500
+ # we'll generate duplicate plots, since a user who set ioff() manually
501
+ # expects to make separate draw/show calls).
502
+ if is_interactive ():
503
+ # ensure current figure will be drawn.
504
+ try :
505
+ _Backend_ipympl ._to_show .remove (figure )
506
+ except ValueError :
507
+ # ensure it only appears in the draw list once
508
+ pass
509
+ # Queue up the figure for drawing in next show() call
510
+ _Backend_ipympl ._to_show .append (figure )
511
+ _Backend_ipympl ._draw_called = True
512
+
498
513
return manager
499
514
500
515
@staticmethod
@@ -523,32 +538,6 @@ def show(block=None):
523
538
if manager .canvas .figure in _Backend_ipympl ._to_show :
524
539
_Backend_ipympl ._to_show .remove (manager .canvas .figure )
525
540
526
- @staticmethod
527
- def draw_if_interactive ():
528
- # If matplotlib was manually set to non-interactive mode, this function
529
- # should be a no-op (otherwise we'll generate duplicate plots, since a
530
- # user who set ioff() manually expects to make separate draw/show
531
- # calls).
532
- if not is_interactive ():
533
- return
534
-
535
- manager = Gcf .get_active ()
536
- if manager is None :
537
- return
538
- fig = manager .canvas .figure
539
-
540
- # ensure current figure will be drawn, and each subsequent call
541
- # of draw_if_interactive() moves the active figure to ensure it is
542
- # drawn last
543
- try :
544
- _Backend_ipympl ._to_show .remove (fig )
545
- except ValueError :
546
- # ensure it only appears in the draw list once
547
- pass
548
- # Queue up the figure for drawing in next show() call
549
- _Backend_ipympl ._to_show .append (fig )
550
- _Backend_ipympl ._draw_called = True
551
-
552
541
553
542
def flush_figures ():
554
543
if rcParams ['backend' ] == 'module://ipympl.backend_nbagg' :
0 commit comments