【问题标题】:Ipython histogram - replace old histogram with new oneIpython histogram - 用新的直方图替换旧的直方图
【发布时间】:2016-03-18 05:55:28
【问题描述】:

我在 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)

【问题讨论】:

  • 你能发布你有什么代码吗?如果不看到现有的东西,就不可能增强。
  • 没问题 - 添加了我拥有的代码的摘要:)

标签: python pandas matplotlib ipython histogram


【解决方案1】:
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(...) 制作图表, 然后在更新循环中l.set_ydata(...)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-31
    • 1970-01-01
    • 2017-07-27
    • 1970-01-01
    • 1970-01-01
    • 2012-10-30
    • 2015-12-05
    • 2016-01-11
    相关资源
    最近更新 更多