Skip to content

{,Range}Slider: accept callable valfmt arguments #30362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 7, 2025

Conversation

doronbehar
Copy link
Contributor

@doronbehar doronbehar commented Jul 27, 2025

PR summary

  • Why is this change necessary? What problem does it solve?

I wanted to create a slider for an "order of magnitude" parameter, that scales logarithmic, but prints concisely the number in the valfmt parameter.

  • What is the reasoning for this implementation?

Somewhat based on the idea here:

Example:

from matplotlib.widgets import Slider
import matplotlib.pyplot as plt

fig, ax=plt.subplots()

s = Slider(
    ax=ax,
    label=r"$\mathcal{O}(x)$",
    valmin=0,
    valmax=1,
    #valfmt=lambda x: f"$10^{{{x:.1f}}}$",
    valfmt=lambda x: f"{(10**x):.0f}"
)
s.on_changed(lambda x: print(10**x))
plt.show()

I'd like to get feedback before writing examples to documentation.

PR checklist

@doronbehar doronbehar marked this pull request as draft July 27, 2025 09:57
@doronbehar doronbehar marked this pull request as ready for review July 27, 2025 12:01
@QuLogic QuLogic requested a review from timhoffm August 1, 2025 02:21
@timhoffm
Copy link
Member

timhoffm commented Aug 1, 2025

This is fundamentally reasonable. I would make the range callable two parameters rather than a sequence.

@doronbehar doronbehar force-pushed the callableSlider_format branch from 41ba77f to 8791358 Compare August 3, 2025 17:11
@doronbehar
Copy link
Contributor Author

This is fundamentally reasonable. I would make the range callable two parameters rather than a sequence.

Done! But it will take me a day to reach the docs updating and release notes etc.

@doronbehar doronbehar marked this pull request as draft August 3, 2025 17:11
@doronbehar
Copy link
Contributor Author

Converted to a draft to reflect that.

@doronbehar doronbehar force-pushed the callableSlider_format branch from 8791358 to 17eb374 Compare August 5, 2025 07:33
@doronbehar doronbehar marked this pull request as ready for review August 5, 2025 07:33
@github-actions github-actions bot added the Documentation: examples files in galleries/examples label Aug 5, 2025
@doronbehar
Copy link
Contributor Author

All docs related changes needed are ready for review.

@doronbehar doronbehar force-pushed the callableSlider_format branch from 17eb374 to b1ca2a5 Compare August 5, 2025 07:36
@doronbehar doronbehar force-pushed the callableSlider_format branch 3 times, most recently from 10569c3 to 2e45041 Compare August 6, 2025 09:16
@doronbehar
Copy link
Contributor Author

Indeed my phrasings aren't always concise :) It's OK. Thanks for the review, fixed them all.

@doronbehar doronbehar force-pushed the callableSlider_format branch from 0caff5c to 41ad716 Compare August 7, 2025 00:13
@github-actions github-actions bot removed the Documentation: examples files in galleries/examples label Aug 7, 2025
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
@doronbehar doronbehar force-pushed the callableSlider_format branch from 41ad716 to e715a5a Compare August 7, 2025 07:16
@doronbehar
Copy link
Contributor Author

Done :).

Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
@doronbehar doronbehar force-pushed the callableSlider_format branch from 0557c76 to b6d7441 Compare August 7, 2025 07:56
@QuLogic QuLogic merged commit 40a47e5 into matplotlib:main Aug 7, 2025
35 of 39 checks passed
@QuLogic QuLogic added this to the v3.11.0 milestone Aug 7, 2025
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.

3 participants