我有一个ipython程序,它有两个下拉菜单和一个按钮。当我点击按钮时,我想使用下拉列表中的信息搜索数据帧,然后并排创建两个直方图。我已经测试了我的代码从数据帧检索信息,这是工作正常的,我可以制作我需要的新直方图。我要做的是从下拉列表中选择一个新的直方图来更新旧的直方图。目前,它们只是出现在前几个版本的下方。
我该怎么做呢?
Tldr:如何使用新信息更新现有图表?
编辑:下面是我的代码摘要
fig = plt.figure(figsize=(10,10))
ax1 = fig.add_subplot(121)
ax2 = fig.add_subplot(122)
# Function to find results
def search(btn):
plt.clf()
ax1.hist(results_df1.COLUMNA.dropna().values, bins=180/5, range=(-60,120))
ax2.hist(results_df4.COLUMNA.dropna().values, bins=180/5, range=(-60,120))
plt.show(fig)
# Button to enter information
btn = widgets.Button(description="Update")
btn.on_click(search)
display(btn)发布于 2015-12-17 09:32:12
from __future__ import division
import numpy as np
import pylab as p
from notebook import *
from ipywidgets import *
from ipywidgets import interactive
%matplotlib inline
def search():
fig = p.figure(figsize=(10,5))
p.subplot(121)
p.hist(np.random.rand((50)) )
p.subplot(122)
p.hist(np.random.rand((50)) )
p.show()
return HTML() # makes it flicker free
interact_manual(search )上面的方法对我来说是可行的。不过,我正在重新绘制整个图形,而不仅仅是更新数据,这也可以完成:使用l,=p.plot(...)创建图形,然后在update循环中使用l.set_ydata(...)。
https://stackoverflow.com/questions/34238455
复制相似问题