【发布时间】:2021-03-30 11:27:16
【问题描述】:
找到此代码here。
%matplotlib inline
from ipywidgets import interactive
import matplotlib.pyplot as plt
import numpy as np
def f(m, b):
plt.figure(2)
x = np.linspace(-10, 10, num=1000)
plt.plot(x, m * x + b)
plt.ylim(-5, 5)
plt.show()
interactive_plot = interactive(f, m=(-2.0, 2.0), b=(-3, 3, 0.5))
output = interactive_plot.children[-1]
output.layout.height = '350px'
interactive_plot
它创建了一个可以交互且不会闪烁的情节。我查看了文档,但我不知道如何添加一个框来控制这个情节?例如,我将如何使用这个 hbox 来更新情节?
items = [widgets.FloatSlider(value=5, min=0, max=10, step=0.01,
orientation='vertical', layout=Layout(width="15px"), readout_format='.0f')
for i in range(5)]
hbox = widgets.HBox(items)
hbox
如果您知道答案,请详细说明并解释为什么会这样。
我尝试从observe 调用函数f,它只是创建了新的不相关图。
当从交互式调用相同的函数时,它的效果非常好。
【问题讨论】:
标签: matplotlib jupyter-notebook ipywidgets