Histogram update in a for loop with matplotlib.pylab

histogram, matplotlib, python

Solution

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:

This:

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

becomes:

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

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

Problem

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() ```

Original source