Skip to content
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

FloatLogSlider widget. #7693

Open
yipihey opened this issue Feb 8, 2025 · 1 comment
Open

FloatLogSlider widget. #7693

yipihey opened this issue Feb 8, 2025 · 1 comment

Comments

@yipihey
Copy link

yipihey commented Feb 8, 2025

Issue

When working with float values that have a very large range of possible values it is very helpful to be able to specify the range with their log values.
ipywidgets provides such a slider as FloatLogSlider. Note that the current value is displayed in scientific notation and one can still edit it by clicking on it.

Possible solution(s)

It would be helpful to add such a FloatLogSlider that works as the ipywidgets example and otherwise be identical to the existing FloatSlider.

Alternatively, or perhaps in addition it could be nice to add a scaling function to the FloatSlider which would allow to specify general scaling functions. Just like one often does for image scaling to implement gamma correction, arcsinh, log10, ln, etc. scaling it would be very nice to allow general functions here. E.g. working with a statistical distribution one could make a slider that has a linear response to the percentiles of the distributions making it easier to specify specific values from the distribution.

Some inspiration can be found how matplotlib implements this for color scaling and how powerful the functionality is:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
gamma = 2.0  # Change for different effects
def gamma_forward(x):
    return np.power(x, 1/gamma)
def gamma_inverse(x):
    return np.power(x, gamma)
gamma_norm = mcolors.FuncNorm((gamma_forward, gamma_inverse), vmin=0, vmax=2)
data = np.random.random(size=(100,100))
c = plt.imshow(data, norm=gamma_norm, cmap='inferno')
plt.colorbar(c,shrink=0.5);

It requires us to give both the forward and reverse functions, yet makes it easy and short to specify our custom function.

Adding this functionality to FloatSlider start and end would be analogous to the vmin vmax in the example above.

Alternatives

I have used the ipywidget slider and it works but it cumbersome to keep two different interfaces and call signatures. I currently am using a FloatInput field instead of a slider which works but does take away from the interactivity of the resulting app.

@yipihey yipihey changed the title LogFloatSlider widget. FloatLogSlider widget. Feb 8, 2025
@Coderambling
Copy link
Contributor

Coderambling commented Feb 8, 2025

See initial question and subsequent discussion on Discord here:

https://discord.com/channels/1075331058024861767/1088157184489164831/1337482001527083008

Code snippets from that discussion:

from bokeh.models.formatters import LogTickFormatter

float_slider = pn.widgets.FloatSlider(name='Float Slider', start=0, end=3.141, step=0.01, value=1.57, format=LogTickFormatter())

float_slider

BasicTickFormatter(use_scientific=True,precision=4)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants