FloatSlider
控件包含readout_format
属性。只需将其设置为所需的精度即可,例如: readout_format='.2f'
。widgets.FloatSlider(value=7.5, min=0, max=10.0,
step=0.001, readout_format='.3f')
在这里找到解决方案here
值在计算过程中以某种方式计算,可能无法使用FloatSlider完成。您可以使用SelectionSlider代替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])
如果您的函数具有return
值,并且在下方标签中显示所需的精度(如图像中所示),则您的代码将正常工作。
主要参考自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:',))