Skip to content

Fix Slider and RangeSlider to notify observers before drawing - #32533

Open
A-Raphie wants to merge 1 commit into
matplotlib:mainfrom
A-Raphie:fix/slider-notify-before-draw
Open

A-Raphie wants to merge 1 commit into
matplotlib:mainfrom
A-Raphie:fix/slider-notify-before-draw

Conversation

@A-Raphie

Copy link
Copy Markdown

PR summary

Fixes #32526. Slider.set_val and RangeSlider.set_val called canvas.draw_idle() before processing the 'changed' observers, so an app whose callback updates other artists paid two renders per event — and the first render showed the previous data. On the reporting app this halved the interactive frame rate (49 ms of a 97 ms event was the wasted render).

This reorders both methods to notify observers first and draw once afterwards. A callback that calls draw_idle() itself still gets exactly one render of the final state; a callback that doesn't draw keeps the widget's own draw. There is no case where the old ordering produced output the new ordering loses — the old first render was stale by construction.

The repro from the issue now reports zero draws before the callback:

drawon=True   draws before the callback ran: 0   draws in total: 1

Both Slider and RangeSlider are covered; the other draw_idle call sites in widgets.py (Cursor, MultiCursor) draw in event handlers, not before callbacks, and are untouched.

AI Disclosure

The reproduction and diagnosis were assisted by an AI coding agent, verified independently by me (matching the issue reporter's workflow). The ordering change is two three-line moves reviewed against the observer contracts in CallbackRegistry.

PR quality check

  • Follows the PR guidelines
  • Tests added (parametrized over Slider and RangeSlider)
  • No documentation changes needed (ordering now matches what users expect; docstrings don't document the old order)

Closes #32526.

set_val drew the canvas before processing the 'changed' callback, so a
callback that updates other artists paid two renders per event and the
first showed the previous data. Notify observers first, then draw once;
a callback that draws itself still sees exactly one render of the final
state.
@github-actions

Copy link
Copy Markdown

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.
Please let us know if (and how) you use AI, it will help us give you better feedback on your PR.

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@github-actions github-actions Bot added topic: widgets/UI first-contribution AgentScan: mixed AgentScan detected an account with mixed automation signals. labels Oct 23, 2026
@iccir

iccir commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

After looking at the author's other PRs and lack of following templates, I believe that the PR summary and PR itself were written by AI and are in violation of our AI policy. AgentScan currently categorizes the account as
Mixed with activity close to automation signals
.

I am marking this PR as Autoclose.

@iccir iccir added the status: autoclose candidate PRs that are not yet ready for review and may be automatically closed in two weeks label Oct 23, 2026
@github-actions

Copy link
Copy Markdown

⏰ This pull request might be automatically closed in two weeks from now.

Thank you for your contribution to Matplotlib and for the effort you have put into this PR. This pull request does not yet meet the quality and clarity standards needed for an effective review. Project maintainers have limited time for code reviews, and our goal is to prioritize well-prepared contributions to keep Matplotlib maintainable.

Matplotlib maintainers cannot provide one-to-one guidance on this PR. However, if you ask focused, well-researched questions, a community member may be willing to help. 💬

To increase the chance of a productive review:

As the author, you are responsible for driving this PR, which entails doing necessary background research as well as presenting its context and your thought process. If you are a new contributor, or do not know how to fulfill these requirements, we recommend that you familiarize yourself with Matplotlib's development conventions or engage with the community via our Discourse or one of our meetings before submitting code.

If you substantially improve this PR within two weeks, leave a comment and a team member may remove the status: autoclose candidate label and the PR stays open. Cosmetic changes or incomplete fixes will not be sufficient. Maintainers will assess improvements on their own schedule. Please do not ping (@) maintainers.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AgentScan: mixed AgentScan detected an account with mixed automation signals. first-contribution status: autoclose candidate PRs that are not yet ready for review and may be automatically closed in two weeks topic: widgets/UI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Slider.set_val renders the figure before it notifies its observers, sometimes causing two renders per event

2 participants