Ipywidgets how to change slider display value
In jupyter, I have the following code to create a slider control for my r variable using ipywidgets.
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets
r = 0.9992
def sl(r=0.9992):
global ar
ar = r
interact(sl, r=(0.999, 1, 0.0001))
This works, but the problem is that the slider value is rounded to 2 decimal places. As a result, the display always shows 1.00.
Is there a way to display its actual value?
+5
source to share
2 answers
Found solution here
The values ββare somehow computed along the path, and it might not be possible to do this with FloatSlider. You can use SelectionSlider instead of Float.
my_values = [i / 1000 for i in range(10)] # [0.001, 0.002, ...] Or use numpy to list
SelectionSlider(options=[("%g"%i,i) for i in my_values])
0
source to share
Your code works if your function matters return
and displays the precision you want to see in the label below (like in the image)
mostly from info @ http://test-widgets.readthedocs.io/en/latest/examples/Using%20Interact.html
from ipywidgets import *
from IPython.display import display
def SL(r):
return r
interact(SL,r=widgets.FloatSlider(value=0.9992,min=0.9990,max=1.0000,step=0.0001,description='Precision:',))
-1
source to share