Here is my test code.
import os
import matplotlib.pyplot as plt
import numpy as np
a = np.arange(10)
bb, cc = np.meshgrid(a, a)
u = np.random.randint(2, 4, (10, 10))
v = np.random.randint(2, 4, (10, 10))
fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(111)
plt.subplots_adjust(left=0.07, bottom=0.01, right=0.95,
top=0.94, hspace=0.0, wspace=0.0)
for i in range(10):
u = np.random.randint(2, 4, (10, 10))
v = np.random.randint(2, 4, (10, 10))
ws = np.sqrt(u**2 + v**2)
cf = plt.contourf(bb, cc, ws)
cb = plt.colorbar(cf)
fig.canvas.update()
fig.canvas.flush_events()
plt.savefig('test_barb/%i.png' % i, dpi=200)
for c in cf.collections:
c.remove()
cb.remove()
What I find confusing here is that the output images get smaller and smaller the more frames I draw. Is there any way to prevent that from happening?