Viktor Kerkez提供的解决方案对我无效(matplotlib版本为3.4.2)。我得到了
user3015729报告的相同错误。以下是经过调整的版本,它能够产生相同的结果,并且可以在matplotlib 3.4.2中正常工作。
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation
from mpl_toolkits.mplot3d import Axes3D
def randrange(n, vmin, vmax):
return (vmax - vmin) * np.random.rand(n) + vmin
n = 100
xx = randrange(n, 23, 32)
yy = randrange(n, 0, 100)
zz = randrange(n, -50, -25)
fig = plt.figure()
ax = Axes3D(fig)
scat = ax.scatter(xx, yy, zz, marker='o', s=20, c="goldenrod", alpha=0.6)
def init():
ax.view_init(elev=10., azim=0)
return [scat]
def animate(i):
ax.view_init(elev=10., azim=i)
return [scat]
anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=360, interval=20, blit=True)
anim.save('basic_animation.mp4', fps=30, extra_args=['-vcodec', 'libx264'])