使用中设置滑块中的默认值

2024-03-29 05:35:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图根据this文档,在jupyter笔记本中使用interact为滑块设置一个默认值。在

虽然“最小值”(min)、“最大值”(max)和“阶跃”(step)的值工作正常

from ipywidgets import interact

def f(x):
    return x

interact(f, x=(5,20,5))

我无法传递初始默认值15,尝试执行以下操作时总是出错:

^{pr2}$

或者

interact(f, x=(min=5,max=20,step=5,value=15))

错误消息显示:

ValueError: (5, 20, 5, 15) cannot be transformed to a widget

或者

Syntax error

我错过了什么?在


Tags: from文档importreturndefstep笔记本jupyter
2条回答

我在jupyter笔记本上使用python3.4,使用Linux。我要做的是:

from ipywidgets import interact, widgets


def f(x):
    return x

interact(f, x=widgets.IntSlider(min=5,max=20,step=5,value=15));

看看Bokeh的文档!在

Click me!

根据您的需要转换此代码:

from bokeh.io import output_file, show
from bokeh.layouts import widgetbox
from bokeh.models.widgets import Slider

output_file("slider.html")

slider = Slider(start=0, end=10, value=1, step=.1, title="Stuff")

show(widgetbox(slider))

我希望这对你有帮助。我在路上。如果你需要更多的支持就告诉我。在

谨致问候, 费边

相关问题 更多 >