使用matplotlib.pylab在for循环中更新直方图 [英] Histogram update in a for loop with matplotlib.pylab

查看:89
本文介绍了使用matplotlib.pylab在for循环中更新直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更新for直方图数据.但我不知道该怎么做 我尝试了set_data,但无法正常工作. 这是代码:

I am trying to update in for loop a histogram data. but I don't know how to make it. I tried with set_data but it is not working. here is the code:

plt.ion()
ax=plt.subplot(111)
[n,X, V]=ax.hist(range(MAX_X),bins=33,normed=True)

....

alternative=defaultdict(list)
...



for z in range(0,max(alternative)):
stat=zeros(33,int)
for i in range(len(alternative[z])):
    stat[alternative[z][i]]+=1

[n,X, V].set_data(stat)// problem here!!!!!!!
plt.draw()

推荐答案

所以问题出在以下事实:[n,X,V]是没有set_data方法的列表.据我所知,没有一种简单的方法可以按照您描述的方式更新"直方图,而无需手动重新排序和组织基础的Patches对象.

So the problem comes from the fact that [n,X,V] is a list with no set_data method. As far as I am aware, there is no easy way to "update" a histogram in the way you describe without manually reordering and organising the underlying Patches objects.

您每次清除轴都将重新绘制也一样:

You would be just as well clearing the axis are replotting each time:

此:

[n,X, V].set_data(stat)// problem here!!!!!!!
plt.draw()

成为:

ax.cla()
[n,X, V]=ax.hist(stat,bins=33,normed=True)
plt.draw()

假定stat是要直方图的数组.

Assuming that stat is an array that you want to histogram.

这篇关于使用matplotlib.pylab在for循环中更新直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆