Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add a pre_draw_event event #17168

Copy link
Copy link
Open
Open
Copy link
@anntzer

Description

@anntzer
Issue body actions

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    New featurekeepItems to be ignored by the “Stale” Github ActionItems to be ignored by the “Stale” Github Action

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.