【发布时间】:2021-02-27 11:09:54
【问题描述】:
我目前尝试使用 matplotlib.animation.FuncAnimation 来创建动态烛台,但是当我使用像这样的示例代码 link.
我的python版本是3.7.1
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
fig, ax = plt.subplots()
xdata, ydata = [], []
ln, = plt.plot([], [], 'ro')
def init():
ax.set_xlim(0, 2*np.pi)
ax.set_ylim(-1, 1)
return ln,
def update(frame):
xdata.append(frame)
ydata.append(np.sin(frame))
ln.set_data(xdata, ydata)
return ln,
ani = FuncAnimation(fig, update, frames=np.linspace(0, 2*np.pi, 128),
init_func=init, blit=True)
plt.show()
但作为图像,我得到一个空的数字。 enter image description here
我不知道发生了什么。
所以我来这里寻求你的帮助。
你们所有的回答对我很有帮助,意义重大。 谢谢。
【问题讨论】:
-
Jupyter 中的绘图采用
png格式。所以它不会被动画化。看看this answer。您的代码在 Python 解释器终端中运行良好。 -
@funie200 有点奇怪,我记得以前在 jupyter notebook 里画过 gif,我觉得我脑子有问题,非常感谢。
标签: python python-3.x matplotlib animation jupyter-notebook