我有一些在Spyder中运行的代码,但是当我尝试在Jupiter notebook中运行它时,它不起作用(我尝试将%matplot lib放在单元格的顶部,但只得到了以下错误: AttributeError:'NoneType‘对象没有’lower‘属性)这是代码:
import numpy as np
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import animation
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)
def init():
ax.scatter(xx, yy, zz, marker='o', s=20, c="goldenrod", alpha=0.6)
return fig,
def animate(i):
ax.view_init(elev=10., azim=i)
return fig,
# Animate
anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=360, interval=20, blit=True)有什么想法吗?
发布于 2021-04-06 19:59:42
Jupiter环境不具备渲染动画的能力,因此它似乎使用了HTML视频功能。我是jupyterLab,我总是带着这个运行。
import numpy as np
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import animation
from IPython.display import HTML # updated
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)
def init():
ax.scatter(xx, yy, zz, marker='o', s=20, c="goldenrod", alpha=0.6)
return fig,
def animate(i):
ax.view_init(elev=10., azim=i)
return fig,
# Animate
anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=360, interval=20, blit=True)
plt.close() # updated
HTML(anim.to_html5_video()) # updatedhttps://stackoverflow.com/questions/66968088
复制相似问题