Bigreddot
为我指明了正确的方向:我不必更新
p
直接,但用于生成的元素
p
(这里
Span
). 通过这个,我发现了
this question
其中代码承载解决方案:update
vline.location
.
完整代码:
import hvplot.pandas
import ipywidgets as widgets
import numpy as np
from bokeh.io import push_notebook, show, output_notebook
from bokeh.models import Span
from bokeh.plotting import figure
%matplotlib inline
hist, edges = np.histogram([1, 2, 2])
p = figure()
r = p.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:])
vline = Span(location=0, dimension='height')
p.renderers.extend([vline])
show(p, notebook_handle=True)
def update_hist(x):
vline.location = x
push_notebook()
widgets.interact(update_hist, x = widgets.FloatSlider(min=1, max=2, step = 0.01))
作为一名Python初学者,我仍然经常监督
Python does not have variables
因此,我们可以更改一个元素
x
通过改变
y
.
x = ['alice']
y = x
y[0] = 'bob'
x # is now ['bob] too