Skip to content

ENH: Add opt-in scroll support to Slider - #32619

Open
soconnor0919 wants to merge 4 commits into
matplotlib:mainfrom
soconnor0919:ec602-slider-scroll-pr
Open

soconnor0919 wants to merge 4 commits into
matplotlib:mainfrom
soconnor0919:ec602-slider-scroll-pr

Conversation

@soconnor0919

Copy link
Copy Markdown

PR summary

Closes #30602.

Add Slider(..., scroll=True) so users can make small adjustments by scrolling over a horizontal or vertical slider. Plot authors can enable it where scrolling is useful.

Each nonzero scroll event moves the slider one increment in the scroll direction. A numeric valstep sets the increment. With a sequence, the slider moves to the next allowed value in that direction. With no valstep, it moves by 1% of its range. Scroll updates use the same bounds checks and callbacks as dragging.

The patch also makes toolbar scroll zoom respect the axes’ navigation setting. The regression test checks that scrolling with x held moves the slider without zooming its axes, while the same gesture still zooms the x-axis of a regular plot.

We found this issue while looking for a project for a graduate class and wanted to share what we built upstream (the review or merge outcome has no bearing on our course credit).

Testing

The widget and backend tests reported 249 passed, 1 skipped on the changes at f91ecfd5b3. We tried the original demo with a trackpad and confirmed that the updated gallery example works with a physical mouse wheel on the native macOS backend. A focused Sphinx build rendered the gallery example, API documentation, and release note. A simulated scroll also confirmed that the gallery slider updates the plotted line.

python -m pytest -q lib/matplotlib/tests/test_widgets.py lib/matplotlib/tests/test_backend_bases.py

AI Disclosure

OpenAI GPT-6.2 Sol was used to explore the issue, suggest the changes to make, & determine where the changes should be made.

PR quality check

  • Use an expressive title.
  • New and changed code is tested.
  • Plotting-related features are demonstrated in an example.
  • New features and API changes have release notes.
  • Documentation complies with the general and docstring guidelines.

@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.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ENH]: Scrollable Sliders

1 participant