我有两个图表,希望能够用IPython笔记本小部件进行交互。下面的代码是我尝试做的简化示例。
import matplotlib.pyplot as plt
import IPython.html.widgets as wdg
def displayPlot1(rngMax = 10):
plt.figure(0)
plt.plot([x for x in range(0, rngMax)])
wdg1 = wdg.interactive(displayPlot1, rngMax = wdg.IntSlider(20))
def displayPlot2(rngMax = 10):
plt.figure(1)
plt.plot([x**2 for x in range(0, rngMax)])
wdg2 = wdg.interactive(displayPlot2, rngMax = wdg.IntSlider(10))
wdg.ContainerWidget([wdg.HTML("""<h1>First Plot</h1>"""),
wdg1,
wdg.HTML("""<h1>Second Plot</h1>"""),
wdg2])
第一个问题是它首先显示所有的小部件,然后在最后一个之后连续显示两个图:
title1
widget1
title2
widget2
plot1
plot2
我想要:
title1
widget1
plot1
title2
widget2
plot2
同时似乎整个输出都会在我触摸任何滑块时被覆盖,并且仅显示一个图(正在更改的图)。
我该如何解决这个问题?(如果我将它们分成两个不同的单元格,我可能可以解决它,但我计划做一些更复杂的事情,最终需要在一个单元格中完成)