Take the 2-minute tour ×

i am trying to make some animation using matplotlib.

fig = plt.figure()
ax = fig.gca(projection='3d')

for k in xrange(10):
    ax.plot_surface(X, Y, field.real, rstride=2, cstride=2, cmap=cm.hot,
        linewidth=0, antialiased=False)
    ax.set_zlim3d(-50, 150)
    filename = "out_%d.png" % k

at first i didn't use cla(), so on every iteration i got the same picture (http://dl.dropbox.com/u/4988243/out_0.png). when i added ax.cla() it was ok with animation but i got some unwanted axes which i don't know how to get rid of (http://dl.dropbox.com/u/4988243/out_1.png).

share|improve this question
did you try clearing the figure itself [matplotlib.sourceforge.net/api/…? –  ev-br Sep 20 '11 at 16:36
yeah, i did - doesn't help –  Cubius Sep 21 '11 at 16:00

1 Answer 1

I'm running the latest version of Matplotlib from github on ubuntu 11.04. I wrote a code snippet where I create a new axis instance each time, and this seems to produce the plots that you want with axis intact. The problem you're seeing might just be a bug, but I think this works around it. I made plots of random numbers, just for demonstration purposes.

import numpy
from matplotlib import pyplot

X = numpy.arange(250)
Y = numpy.arange(250)
X, Y = numpy.meshgrid(X, Y)

fig = pyplot.figure()

for ind in range(10):
    Z = numpy.random.random( (250,250) )

    ax = fig.add_subplot(111,projection='3d')
    ax.plot_surface(X, Y, Z, cmap='hot', linewidth=0, cstride = 2, rstride = 2, antialiased=False)
    ax.set_zlim3d(0, 1)
    pyplot.savefig('example' + str(ind) + '.png' )
share|improve this answer

Your Answer


