Repository navigation
Conversation
Slider.set_val called canvas.draw_idle() before notifying 'changed' observers, so a callback updating other artists triggered a stale extra render (two renders per event, the first drawn with previous data). Notify observers first, then request the draw, so the callback's own draw request coalesces with the widget's. Fixes matplotlib#32526
|
Thank you for opening your first PR into Matplotlib! If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks. We also ask that you please finish addressing any review comments on this PR and wait for it to be merged (or closed) before opening a new one, as it can be a valuable learning experience to go through the review process. You can also join us on discourse chat for real-time discussion. For details on testing, writing docs, and our review process, please see the developer guide. We strive to be a welcoming and open project. Please follow our Code of Conduct. |
|
Note on the |
|
I am closing this pull request in accordance with our Policy on Generative AI. The account in question has opened several pull requests across multiple repositories. In addition, AgentScan has detected automation signals from the account. |
What
Fixes #32526.
Slider.set_valcalledcanvas.draw_idle()before notifying'changed'observers, so a callback that updates other artists caused two renders per
event — the first drawn with the previous data. In the reporter's app (four
panels redrawn per slider event) one event cost 97 ms, 49 ms of it the wasted
stale render.
Changes
lib/matplotlib/widgets.py—Slider.set_val: notify'changed'observers first, then request the draw when
drawonis set.self.valisassigned before notification so observers see the new value. A callback's
own
draw_idle()now coalesces with the widget's single draw instead ofproducing a second, stale one. (
RangeSlider.set_valhas the same shapebut is left untouched — out of scope of the reported issue.)
lib/matplotlib/tests/test_widgets.py— new regression testtest_slider_set_val_notifies_before_draw: wrapscanvas.draw_idleandasserts the observer ran before
set_valrequested its draw.Verification
mainwith the issue's scenario (Agg backend):the draw was requested with 0 observer events fired; after the fix the
single draw is requested after the observer ran.
draw_calls == [0]), passes with thefix (
draw_calls == [1]).test_widgets.pyin full: 135 passed, 1 skipped (all 11 slider casespass; 2 image-comparison tests fail only in wheel installs that lack
baseline images — unrelated to this change; they pass when run from the
repo tree).
ruff check(repo-pinned v0.15.20): clean on both changed files.Known limitations
Slider.set_val, andtest_widgets.pyis fully green.AI Disclosure
AI tools assisted in the development of this patch; all changes were reviewed and tested by me, and I take responsibility for them.