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

Add a pre_draw_event event #17168

Open
anntzer opened this issue Apr 17, 2020 · 4 comments
Open

Add a pre_draw_event event #17168

anntzer opened this issue Apr 17, 2020 · 4 comments
Labels
keep Items to be ignored by the “Stale” Github Action New feature

Comments

@anntzer
Copy link
Contributor

anntzer commented Apr 17, 2020

Bug report

Bug summary

draw_event currently fires after the draw has completed (it is triggered at the end of Figure.draw()). This means it cannot modify the Figure, unless one is willing to trigger a second draw -- and even then one needs to be careful to not recurse infinitely. For example, in https://matplotlib.org/3.1.0/gallery/pyplots/auto_subplots_adjust.html (linking the 3.1 version because there's an unrelated bug in 3.2, per #17167), note the call to figure.canvas.draw() at the end of the callback, effectively duplicating the draw(); moreover, if that draw() is moved out of the if block then one gets an infinite recursion. Being able to register a callback to be executed before draw() occurs would avoid both problems.
Likewise a pre-draw callback would provide a very general solution for #17052, by allowing one to simply update the colorbar at pre-draw time.

The same feature was rejected because there wasn't a compelling use case in #5042, but I think I exposed more use cases here. See also #10334 re: recursive redraws.

Matplotlib version

  • Operating system:
  • Matplotlib version: 3.2
  • Matplotlib backend (print(matplotlib.get_backend())):
  • Python version:
  • Jupyter version (if applicable):
  • Other libraries:
@ImportanceOfBeingErnest
Copy link
Member

I'm in favour of this. There might still be cases though where you run into a chicken-or-egg problem (often you only know the size of something after it's beeing drawn).

I would also like to note that for many cases, using a draw_event is just a workaround for knowing when the axes limits change. But there is no general any_axes_lim_changed event. So I think #317 is also still relevant.

@anntzer
Copy link
Contributor Author

anntzer commented Apr 17, 2020

There are a lot of things that people may want to listen to (e.g. in #17052 it's norm limit changes -- and we're not even talking about making this robust for third-party norms too!), so sure, we can in theory add events for everything, but in practice I think a pre_draw_event will be much easier to get in first.

@github-actions
Copy link

This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Jul 26, 2023
@jklymak jklymak added keep Items to be ignored by the “Stale” Github Action and removed status: inactive Marked by the “Stale” Github Action labels Jul 26, 2023
@jklymak
Copy link
Member

jklymak commented Jul 26, 2023

This seems straight forward to add. I think the hardest thing would be to make example use cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keep Items to be ignored by the “Stale” Github Action New feature
Projects
None yet
Development

No branches or pull requests

3 participants