如何将这个转变成3D动画?

2024-04-25 20:31:46 发布

您现在位置:Python中文网/ 问答频道 /正文

from mpl_toolkits import mplot3d
from mpl_toolkits.mplot3d import axes3d
%matplotlib qt

# Create the figure
fig=plt.figure()

# Add an axes
ax = fig.add_subplot(111, projection='3d')

# plot the surface
  # create x,y
xx, yy = np.meshgrid(np.min(z2[:,4]) + ((np.max(z2[:,4])-np.min(z2[:,4]))/9)*range(10),
                     np.min(z2[:,2]) + ((np.max(z2[:,2])-np.min(z2[:,2]))/9)*range(10))
  # calculate corresponding z
z = np.zeros((10,10))

ax.plot_surface(xx, yy, z, alpha=0.8, color='g')

# add the trajectory
ax.plot3D(z2[:,4],
          z2[:,2],
          z2[:,0])
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
ax.view_init(30, 0)
fig;
plt.draw()

我曾尝试使用matplotlib 3d动画,但出现了几个错误。我似乎无法让我的代码遵循matplotlib编写的示例。使用matplotlib 3d动画制作动画的任何帮助都将非常有用


Tags: thefromimportmatplotlibnpfig动画ax