Skip to content

Add a pre_draw_event event #17168

Open
Open
@anntzer

Description

@anntzer

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    New featurekeepItems 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