首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >动画未在Jupiter notebook中运行

动画未在Jupiter notebook中运行
EN

Stack Overflow用户
提问于 2021-04-06 19:49:39
回答 1查看 73关注 0票数 0

我有一些在Spyder中运行的代码,但是当我尝试在Jupiter notebook中运行它时,它不起作用(我尝试将%matplot lib放在单元格的顶部,但只得到了以下错误: AttributeError:'NoneType‘对象没有’lower‘属性)这是代码:

代码语言:javascript
复制
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)

有什么想法吗?

EN

回答 1

Stack Overflow用户

发布于 2021-04-06 19:59:42

Jupiter环境不具备渲染动画的能力,因此它似乎使用了HTML视频功能。我是jupyterLab,我总是带着这个运行。

代码语言:javascript
复制
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()) # updated
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66968088

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档