python-3.x - matplotlib FuncAnimation 无法工作
问题描述
伙计们。我正在尝试通过教程视频了解该FuncAnimation
功能:https://www.youtube.com/watch?v=Ercd-Ip5PfQ&list=PL-osiE80TeTvipOqomVEeZ1HRrcEvtZB_&index=9
,我的开发工具是Google Colaboratory 。但是,它最终无法显示剧情。
这是我的代码:
import random
from itertools import count
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
plt.style.use('fivethirtyeight')
x_vals = []
y_vals = []
index = count()
def animate(i):
x_vals.append(next(index))
y_vals.append(random.randint(0, 5))
plt.cla()
plt.plot(x_vals, y_vals)
ani = FuncAnimation(plt.gcf(), animate, interval=1000)
plt.tight_layout()
plt.show()
最终输出是:
<Figure size 432x288 with 0 Axes>
希望有人能解决这个问题,谢谢。
解决方案
推荐阅读
- r - 创建自己的配色方案,颜色选择
- java - 调整元素列表大小时出现 ConcurrentModificationException
- bash - 有没有办法提前运行 docker 健康检查?
- java - 放心。是否可以从响应 json 中提取 JSONObject/JSONArray?
- javascript - `String.match` 数组的结果如何包含索引、组等?
- docker - Docker Desktop for Windows 无法运行标记图像
- c# - 单元测试自动映射器以返回角色中的用户数
- python - 为什么 np.power() 比 np.exp(np.log()) 慢?
- php - 显示是否在编辑页面中检查了复选框 PHP
- sql - Oracle IDENTITY_VAL_LOCAL() 函数的 SQL Server 等效项