2

I'm trying to use matplotlib.animation in order to animate a surface, but I can't really understand the documentation, anyway this is my code:

import numpy as np
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d.axes3d as p3
import matplotlib.animation as animation
from matplotlib import cm

dimension=1.5   

X=np.arange(-dimension,dimension,0.01)
Y=np.arange(-dimension,dimension,0.01)
X, Y = np.meshgrid(X,Y)

def drum(t):    #only a test, will be edited in future
    Z=(X**2+Y**2)*np.cos(t*0.01)
    return Z

def update_drum(t):
    ax.clear()
    ax.plot_surface(X, Y, drum(t), cmap=cm.coolwarm,
                   linewidth=0, antialiased=False)
    plt.show

# Attaching 3D axis to the figure
fig = plt.figure()
ax = p3.Axes3D(fig)

# Setting the axes properties
ax.set_xlim3d([-dimension-0.5,0.5+dimension])
ax.set_xlabel('X')

ax.set_ylim3d([-dimension-0.5,0.5+dimension])
ax.set_ylabel('Y')

ax.set_zlim3d([-3.0, 3.0])
ax.set_zlabel('Z')

ax.set_title('Resonant modes')

# Creating the Animation object
ani = animation.FuncAnimation(fig, update_drum, 25,
                                   interval=50, blit=True)

And I get as a result this error:

axes = set(a.axes for a in artists)

"TypeError: 'Axes3D' object is not iterable".

So here's my questions:

  • How should I modify the function called by FuncAnimation (update_drum)?
  • How can I solve the error "Axes3D' object is not iterable"?

Thanks

1 Answer 1

2

Try to remove the blit arguement,

If blit=True, func and init_func should return an iterable of drawables to clear.

You're returning a single Axes3D, not an iterable of drawables.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.