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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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

1 participant
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy