【问题标题】:i can't see the animation by using matplotlib.animation我无法使用 matplotlib.animation 看到动画
【发布时间】:2021-03-16 17:28:53
【问题描述】:
import matplotlib.animation as animation
import numpy as np
import matplotlib.pyplot as plt
n = 100
x = np.random.randn(n)

我无法看到这段代码的动画。谁能帮帮我?

#function
def update(curr):

    if curr == n: 
        a.event_source.stop()


    #graphs
    plt.cla()
    bins = np.arange(-4, 4, 0.5)
    plt.hist(x[:curr], bins=bins)
    plt.axis([-4,4,0,30])
    plt.gca().set_title('Sampling the Normal Distribution')
    plt.gca().set_ylabel('Frequency')
    plt.gca().set_xlabel('Value')
    plt.annotate('n = {}'.format(curr), [3,27])

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

【问题讨论】:

  • 您可能需要 plt.ion() 来启用动画...也许?

标签: python matplotlib animation


【解决方案1】:

我没有看到 #function def update(curr): 所以我写了一个关于如何使用 FuncAnimation 方法的长答案,但我认为你需要做的就是添加:plt.show()a = animation.FuncAnimation(fig, update, interval=100)之后

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-23
    • 1970-01-01
    相关资源
    最近更新 更多