我在jupyter笔记本上使用seaborn,想要一个滑块来更新图表。我的代码如下:
from ipywidgets import interact, interactive, fixed, interact_manual
import numpy as np
import seaborn as sns
from IPython.display import clear_output
def f(var):
print(var)
clear_output(wait=True)
sns.distplot(list(np.random.normal(1,var,1000)))
interact(f, var=10);
问题:每次移动滑块时,图形都会重复。如何更新图表?
答案 0 :(得分:3)
Seaborn图应作为常规matplotlib图处理。因此,您需要使用select m.*, firstdp.*, lastdp.*
from dbo.Meters m outer apply
(select top (1) dp.datetime, dp.value
from dbo.DataPoints dp
where dp.MeterId = m.MeterId
order by datetime asc
) firstdp outer apply
(select top (1) dp.datetime, dp.value
from dbo.DataPoints dp
where dp.MeterId = m.MeterId
order by datetime desc
) lastdp;
来显示它,例如answer中所述。
结合plt.show()
魔法命令,这对我来说很好用:
%matplotlib inline
另一种解决方案是更新绘图数据而不是重新绘制新数据,如下所述:https://stackoverflow.com/a/4098938/2699660