|
From: Ignat H. <ig...@gm...> - 2015-02-23 13:53:46
|
Firstly I would like to apologize in case this should belong in the
matplotlib-users, I'm not sure if this is dev or users related.
Let us say we want to animate a 2D contour plot, then passing the blit =
True argument to FuncAnimation fails since the QuadContourSet has no axes
attribute.
Is it for some specific it is implemented like this? And maybe there a hack
to get this to work?
A working code example with the actually wanted one commented out.
import numpy as np
import matplotlib.animation as animation
from matplotlib import pyplot as plt
fig, ax = plt.subplots()
x = np.linspace( -np.pi, np.pi, 50 )
y = np.linspace( -np.pi, np.pi, 50 )
X, Y = np.meshgrid( x, y )
Z = np.zeros( X.shape )
def init():
cont = ax.contourf( X, Y, Z )
cbar = plt.colorbar( cont )
return cont,
def animate( t ):
k = np.array( [1,1] )
omega = 0.5
x = np.linspace( -np.pi, np.pi, 50 )
y = np.linspace( -np.pi, np.pi, 50 )
X, Y = np.meshgrid( x, y )
Z = np.exp( 1j * (omega* t - X*k[0] ) ) * np.exp( - 1j * k[1]*Y )
cont = ax.contourf( X, Y, Z )
return cont,
#ani = animation.FuncAnimation( fig, animate, frames = 100, interval = 1,
repeat = False, blit = True, init_func = init,)
ani = animation.FuncAnimation( fig, animate, frames = 100, interval = 1,
repeat = False, init_func = init,)
plt.show()
|