Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ipywidgets, how to change slider's value display precision

In jupyter,I have the following code to create a slider control for my variable r 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))

It works but the problem is that the display of slider value is rounded to 2 decimal. As a result, the display always show 1.00.

enter image description here

Is there any way to display its actual value?

like image 609
J_yang Avatar asked Mar 31 '17 13:03

J_yang


1 Answers

Since the version 6.x of ipywidgets, FloatSlider contains readout_format attribute. Just set it to your desired precision, e.g. like this:

widgets.FloatSlider(value=7.5, min=0, max=10.0, 
                    step=0.001, readout_format='.3f')
like image 77
Paloha Avatar answered Nov 15 '22 23:11

Paloha