The Wayback Machine - https://web.archive.org/web/20210904161421/https://github.com/matplotlib/matplotlib/pull/17923
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

Dont double draw #17923

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft

Dont double draw #17923

wants to merge 8 commits into from

Conversation

@tacaswell
Copy link
Member

@tacaswell tacaswell commented Jul 14, 2020

PR Summary

Replaces #5800

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/next_api_changes/* if API changed in a backward-incompatible way
@jklymak
Copy link
Contributor

@jklymak jklymak commented Jul 14, 2020

Does this need an API change note?

@dopplershift
Copy link
Contributor

@dopplershift dopplershift commented Jul 14, 2020

I think the intention is that this is not really user-visible except for performance.

@tacaswell
Copy link
Member Author

@tacaswell tacaswell commented Jul 14, 2020

Yes, but I needed the PR number to write it ;)

@jklymak
Copy link
Contributor

@jklymak jklymak commented Jul 14, 2020

Yes, but I needed the PR number to write it ;)

That is a problem with that API re-org structure....

@efiring
Copy link
Member

@efiring efiring commented Jul 14, 2020

To reduce breakage in user code, would it make sense to change pyplot.draw() so that if not interactive it calls figure.canvas.draw()?

Copy link
Member

@efiring efiring left a comment

slight edit, and some questions

For backends that do not have an event loop associated with them
(e.g. non-GUI backends) the semantics of `.FigureCanvasBase.draw_idle` are
not clear. Previously it was equivalent to a non-re-entrant
``fig.canvas.draw()`` call in all cases. Now it will be a no-op if

This comment has been minimized.

@efiring

efiring Jul 14, 2020
Member

delete "if"

not clear. Previously it was equivalent to a non-re-entrant
``fig.canvas.draw()`` call in all cases. Now it will be a no-op if
unless Matplotlib is in "interactive mode" (as given by
`matplotlib.is_interacitve`).

This comment has been minimized.

@efiring

efiring Jul 14, 2020
Member

-> "is_interactive()"

lib/matplotlib/tests/test_collections.py Show resolved Hide resolved
def draw_all_when_not_interactive():
for f_mgr in plt._pylab_helpers.Gcf.get_all_fig_managers():
if f_mgr.canvas.figure.stale:
f_mgr.canvas.draw()

This comment has been minimized.

@efiring

efiring Jul 14, 2020
Member

Can this function be eliminated by switching to interactive mode? If so, that seems like a better test.

This comment has been minimized.

@tacaswell

tacaswell Aug 5, 2021
Author Member

no, because we would never hit the "idle" case to actually let things draw, however I this can be done with direct call to fig.canvas.draw() (as we have the figures here!).

@tacaswell
Copy link
Member Author

@tacaswell tacaswell commented Jul 15, 2020

To reduce breakage in user code, would it make sense to change pyplot.draw() so that if not interactive it calls figure.canvas.draw()?

I am wary of adding more special cases here. The new behavior is now much closer to what the GUI backends do (in which draw_idle schedules a draw the next time the GUI event loops spins at some indeterminate time in the future.

@jklymak jklymak marked this pull request as draft Aug 17, 2020
@tacaswell tacaswell modified the milestones: v3.4.0, v3.5.0 Feb 3, 2021
@tacaswell tacaswell force-pushed the tacaswell:dont-double-draw branch from 84fdda2 to ba230ee Aug 5, 2021
@tacaswell tacaswell marked this pull request as ready for review Aug 5, 2021
@tacaswell tacaswell force-pushed the tacaswell:dont-double-draw branch from ba230ee to d4a34fc Aug 5, 2021
@tacaswell tacaswell requested a review from efiring Aug 5, 2021
@efiring
Copy link
Member

@efiring efiring commented Aug 10, 2021

I like Jody's suggestion to use draw_no_output directly, instead of indirectly via figure.canvas.draw.

Regarding pyplot.draw: the upshot seems to be that it has always been inherently confusing. The docstring implies it is useless--especially as part of pyplot, which is supposed to be the simplest interface. If I understand correctly, this PR makes it even more useless than it was. As in the tests you are changing, what the pyplot user really needs to do is probably draw_no_output, not draw_idle. In that case, this PR is making pyplot.draw more internally consistent, but in all the cases that matter in user code, it is silently making it useless, when before it was useful precisely because of its internal inconsistency.

@tacaswell tacaswell modified the milestones: v3.5.0, v3.6.0 Aug 12, 2021
@tacaswell
Copy link
Member Author

@tacaswell tacaswell commented Aug 12, 2021

Pushed this to 3.6 to keep kicking the can of thinking this through down the road.

I tried doing a blind fig.canvas.draw() -> fig.draw_no_output() conversion in all of the tests and found 3 cases where we were actually relying on exercising the backend render logic so I am not sure it is safe to do that blind conversion (2 of them were expected failures one actually looked at the RGBA from Agg). I could easily believe that some of the tests are showing that the happy paths are happy.

On the bright side there are only ~150 of them.

@tacaswell tacaswell marked this pull request as draft Aug 12, 2021
@jklymak
Copy link
Contributor

@jklymak jklymak commented Aug 12, 2021

Certainly I wasn't suggesting we change all of them, at least here - just the new ones you added in this PR (if they work)!

@tacaswell
Copy link
Member Author

@tacaswell tacaswell commented Aug 12, 2021

Yeah, but it was less work to use sed to change them all :-p

@tacaswell tacaswell force-pushed the tacaswell:dont-double-draw branch from d27c713 to 7924d7e Aug 13, 2021
@tacaswell tacaswell force-pushed the tacaswell:dont-double-draw branch from 7924d7e to 9bd2702 Aug 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants