Rectangle 27 8

To clear the plot use p.clf

def simpledist(speclist,totalbugs,a):
    data = [float(spec.pop)/float(totalbugs) for spec in speclist]
    p.clf()
    p.hist(data)
    p.savefig('/Home/s1215235/Documents/python/newfolder/' + str(a) + '.png')

presuming that p is a matplotlib.pyplot or figure instance, also what @bernie says - that would work fine too.

If you've already set up your title, axis labels etc then this will nuke all those settings. Better would be to do as he says and try

p.gca().cla()

You might also want to suggest p.gca().cla(), so that if you have a figure title, etc and you don't want to redo all that, just update the axes. I imagine there is a more complicated way to update the data of a histogram too.

python - Stop pylab overlaying plots? - Stack Overflow

python matplotlib overlay
Rectangle 27 0

You cannot use interactive more (ion) in a console. Unfortunately the question is not very clear on what you want; but let's suppose you want to show a window with the plot that is animated. An easy way to get that would be to run the script outside an IPython console. In spyder you'd go to Run/Configure (or press F6) and select "Execute in a new dedicated Python console".

Now the problem with the script itself is that you first call plt.show(), which shows empty subplots. This has to be removed.

A version which would show an animation would be

import numpy as np
import matplotlib.pyplot as plt

plt.close('all')
plt.ion()

tmax =30

fig, ax = plt.subplots(2,3)     

for t in range (1, tmax):
    W = np.random.rand(6,100)      
    for ii in range(2):
        for jj in range(3):      
            output = W[3*ii+jj,:].reshape((10,10),order = 'F')
            ax[ii,jj].clear()
            ax[ii,jj].imshow(output, interpolation='nearest')
    if t == 1:                
        plt.tight_layout()
    plt.draw()
    plt.pause(0.1)


plt.waitforbuttonpress()

The important part for me was: "Now the problem with the script itself is that you first call plt.show(), which shows empty subplots. This has to be removed."

python - tight_layout throw error: ValueError: max() arg is an empty s...

python matplotlib spyder