【问题标题】:Animation not working in matplotlib python动画在matplotlib python中不起作用
【发布时间】:2020-07-25 15:44:02
【问题描述】:

我正在做我的第一个 matplotlib 动画图。而且它不起作用。请有人解释一下,为什么??

import matplotlib.animation as animation
import matplotlib.pyplot as plt
import numpy as np

n = 100
X = np.random.randn(n)

def update(curr):
    if curr == n:
        a.event_source.stop()
    plt.cla()
    bins = np.arange(-4,4, 0.5)
    plt.hist(X[:curr], bin=bins)
    plt.axis([-4,4,0,30])
    plt.annotate("n={}".format(curr),(3,27))
  

fig = plt.figure()
a = animation.FuncAnimation(fig, update, interval=100)

附:我在 jupyter notebook 上编码

【问题讨论】:

  • 你试过plt.show()吗?
  • 是的。试过了,没用。
  • 能否请您提供完整的可重现代码? curr 变量无法识别。
  • 其实我正在做一个数据可视化的 coursera 课程,教授告诉我,corr 是一个递归变量,每次函数运行后都会自动更新。
  • 哦,我明白了。我建议你在 coursera 论坛上问这个。

标签: python-3.x matplotlib-animation


【解决方案1】:

我得到了答案。这是 plt.hist 调用中的错字。参数是bins 不是bin
plt.hist(X[:curr], bins=bins)

【讨论】:

    猜你喜欢
    • 2015-03-03
    • 2018-06-19
    • 2021-11-18
    • 2016-06-21
    • 2020-08-13
    • 2014-10-09
    • 2017-06-08
    • 2011-03-27
    • 2023-03-13
    相关资源
    最近更新 更多