慕容3067478
确实有很多选择,我不确定什么是最好的,但我经常使用散景并对此感到高兴。下面的示例可以帮助您入门。要启动它,请在保存脚本的目录中打开一个 cmd 并运行“bokeh serve script.py --show --allow-websocket-origin=*”。from bokeh.plotting import figurefrom bokeh.io import curdocfrom bokeh.models.widgets import Sliderfrom bokeh.models import Row,ColumnDataSource#create the starting datax=[0,1,2,3,4,5,6,7,8]y_noise=[1,2,2.5,3,3.5,6,5,7,8]slope=1 #set the starting value of the slopeintercept=0 #set the line to go through 0, you can change this latery= [slope*i + intercept for i in x]#create the y data via a list comprehension# create a plotfig=figure() #create a figuresource=ColumnDataSource(dict(x=x, y=y)) #the data destined for the figurefig.circle(x,y_noise)#add some datapoints to the plotfig.line('x','y',source=source,color='red')#add a line to the figure#create a slider and update the graph source data when it changesdef updateSlope(attrname, old, new): print(str(new)+" is the new slider value") y = [float(new)*i + intercept for i in x] source.data = dict(x=x, y=y) slider = Slider(title="slope", value=slope, start=0.0, end=2.0,step=0.1)slider.on_change('value', updateSlope)layout=Row(fig,slider)#put figure and slider next to eachothercurdoc().add_root(layout)#serve it via "bokeh serve slider.py --show --allow-websocket-origin=*"allow-websocket-origin=* 是允许其他用户访问服务器并查看图表。http 将是http://yourPCservername:5006/(5006 是默认的散景端口)。如果您不想从您的 PC 上提供服务,您可以订阅像 Heroku 这样的云服务:example。