Skip to content

Commit 8a3740d

Browse files
authored
Merge pull request #468 from anntzer/udif
Move draw_if_interactive logic to new_figure_manager_given_figure.
2 parents 913431e + 73d1af2 commit 8a3740d

File tree

1 file changed

+15
-26
lines changed

1 file changed

+15
-26
lines changed

ipympl/backend_nbagg.py

+15-26
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,21 @@ def destroy(event):
495495
Gcf.destroy(manager)
496496

497497
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+
498513
return manager
499514

500515
@staticmethod
@@ -523,32 +538,6 @@ def show(block=None):
523538
if manager.canvas.figure in _Backend_ipympl._to_show:
524539
_Backend_ipympl._to_show.remove(manager.canvas.figure)
525540

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-
552541

553542
def flush_figures():
554543
if rcParams['backend'] == 'module://ipympl.backend_nbagg':

0 commit comments

Comments
 (0)