擅长:python、mysql、java
<p>好吧,我想我找到了一个很好的解决办法:</p>
<pre><code>def line(a=0,b=0):
x = np.arange(-10,10)
y = a+x*b
plt.xlim((-10,10))
plt.ylim((-10,10))
plt.plot(x, y)
sliders = widgets.interact(a=(-10,10,0.1), b=(-10,10,0.1))
def test(chose_defaults):
if chose_defaults=="a":
@sliders
def h(a=5,b=5):
return(line(a,b))
if chose_defaults=="b":
@sliders
def h(a=0,b=1):
return(line(a,b))
widgets.interact(test, chose_defaults=["a","b"])
</code></pre>
<p>上面的代码基本上嵌套了两个小部件。首先,显示用于选择场景的单独小部件;场景的操作是仅在默认设置中不同的绘图</p>