Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move draw_if_interactive logic to new_figure_manager_given_figure. #468

Merged
merged 1 commit into from
Jun 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 15 additions & 26 deletions ipympl/backend_nbagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,21 @@ def destroy(event):
Gcf.destroy(manager)

cid = canvas.mpl_connect('close_event', destroy)

# Only register figure for showing when in interactive mode (otherwise
# we'll generate duplicate plots, since a user who set ioff() manually
# expects to make separate draw/show calls).
if is_interactive():
# ensure current figure will be drawn.
try:
_Backend_ipympl._to_show.remove(figure)
except ValueError:
# ensure it only appears in the draw list once
pass
# Queue up the figure for drawing in next show() call
_Backend_ipympl._to_show.append(figure)
_Backend_ipympl._draw_called = True

return manager

@staticmethod
Expand Down Expand Up @@ -523,32 +538,6 @@ def show(block=None):
if manager.canvas.figure in _Backend_ipympl._to_show:
_Backend_ipympl._to_show.remove(manager.canvas.figure)

@staticmethod
def draw_if_interactive():
# If matplotlib was manually set to non-interactive mode, this function
# should be a no-op (otherwise we'll generate duplicate plots, since a
# user who set ioff() manually expects to make separate draw/show
# calls).
if not is_interactive():
return

manager = Gcf.get_active()
if manager is None:
return
fig = manager.canvas.figure

# ensure current figure will be drawn, and each subsequent call
# of draw_if_interactive() moves the active figure to ensure it is
# drawn last
try:
_Backend_ipympl._to_show.remove(fig)
except ValueError:
# ensure it only appears in the draw list once
pass
# Queue up the figure for drawing in next show() call
_Backend_ipympl._to_show.append(fig)
_Backend_ipympl._draw_called = True


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