def update_points(num):
'''
更新数据点
'''
point_ani.set_data(x[num], y[num], z[num], "ro")
return point_ani,
fig = plt.figure(figsize=(12,5),tight_layout=True)
第一个子图的坐标系设置为3D
theta = np.linspace(-4 * np.pi, 4 * np.pi, 100) # 角度
z = np.linspace(-2, 2, 100) # Z坐标
r = z**2 + 1 # 半径
x = r * np.sin(theta) # X坐标
y = r * np.cos(theta) # y坐标
ax2 = plt.subplot(111,projection = "3d")
ax2.plot(x, y, z) #绘制曲线
point_ani, = ax2.plot([x[0]], [y[0]], [z[0]], "ro")
#ax2.scatter3D(x,y,z,c = "r") #绘制红色三维散点
ax2.view_init(elev=20,azim=25) # 设置轴的方位角和高程
ax2.set_title("Curve and scatter")
ani = animation.FuncAnimation(fig, update_points, np.arange(0, 100), interval=50, blit=True)
plt.show()
以上是源代码,另外该导的库全部都导入了。没有报错