matplotlib / ipympl

Matplotlib Jupyter Integration
https://matplotlib.org/ipympl/
BSD 3-Clause "New" or "Revised" License
1.59k stars 225 forks source link

Move draw_if_interactive logic to new_figure_manager_given_figure. #468

Closed anntzer closed 2 years ago

anntzer commented 2 years ago

Currently, Matplotlib only ever calls draw_if_interactive at the end of plt.figure() (and upon figure unpickling), i.e. this is a mechanism to further customize handling of newly generated figures. (Prior to Matplotlib 1.5, draw_if_interactive was also called at the end of all pyplot functions to trigger a figure redraw, but this is now handled by the stale attribute.)

In order to simplify the backend API ("what is the API that a backend module must/can provide", I am planning to deprecate (on Matplotlib's side) the ability for backends to provide a draw_if_interactive function (forcing them to always do if interactive(): draw_idle()) (https://github.com/matplotlib/matplotlib/issues/23105). Instead, any relevant new-figure-customization logic can instead go into new_figure_manager_given_figure. This PR implements this change for ipympl, and should be fully back-compatible all the way back to Matplotlib 1.5. I would like to make these changes first on the side of the clients (i.e., the third-party backends), to catch any possible problems with the intended change on Matplotlib's side.

github-actions[bot] commented 2 years ago

Binder :point_left: Launch a binder notebook on branch anntzer/ipympl/udif

anntzer commented 2 years ago

As for #466, the visual regression tests fail even on master, independently of this PR.

anntzer commented 2 years ago

@ianhi any chance you can have a look at this? thanks :)

ianhi commented 2 years ago

and thanks also for the PR! makes following the backend changes in matplotlib much nicer :)