Python FuncAnimation问题:Matplotlib中基于事件的动画

Python FuncAnimation问题:Matplotlib中基于事件的动画,python,arrays,animation,numpy,matplotlib,Python,Arrays,Animation,Numpy,Matplotlib,这是一个关于Matplotlib的FuncAnimation方法的简单问题。我什么都试过了,但都没用 我正在编写一个代码,允许用户在im显示图上选择一条水平线,这样他们就可以看到对应于每个像素(y轴)的阵列的计算结果,其中每个点对应于另一个预定的numpy阵列。x-数组(一组x-值被标记为长度为1024的“lambda_数组”,y值被标记为“强度_形”,并且在[10][256][1024]形数组中,或者简单地说是[y][x][values]。本质上,我希望动画在强度_形[y][x+I][2:va

这是一个关于Matplotlib的FuncAnimation方法的简单问题。我什么都试过了,但都没用

我正在编写一个代码,允许用户在im显示图上选择一条水平线,这样他们就可以看到对应于每个像素(y轴)的阵列的计算结果,其中每个点对应于另一个预定的numpy阵列。x-数组(一组x-值被标记为长度为1024的“lambda_数组”,y值被标记为“强度_形”,并且在[10][256][1024]形数组中,或者简单地说是[y][x][values]。本质上,我希望动画在强度_形[y][x+I][2:values]上迭代,而我是迭代器

这个问题与水平线或事件处理无关,我只是无法让“FuncAnimation”方法正常工作……它创建了一个新窗口,但其中没有任何内容。我确定了三个可能的假设:1)我可能错过了函数工作的简单步骤2)与numpy阵列存在某种不兼容3)我需要使用“plt.draw”重新绘制它,我没有这样做

对于知道如何使用Matplotlib制作动画的人来说,这应该是相对简单的

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

plt.ion()

fig_anim = plt.figure("Animation")
graph, = plt.plot([],[], '-r')

def init_graph():
    graph.set_data((lambda_array), intensity_shaped[5][50][2:]) #<- these are both numpy arrays.
    return graph,


def animate(k):
    graph.set_ydata(intensity_shaped[5][50+k][2:])
    return graph,

def animate_func():
    anim = animation.FuncAnimation(fig_anim,animate,
                             init_func=init_graph,
                             frames =100, interval = 50) 
    plt.draw()
    return anim

animate_func()    #<- this doens't work alone

animation.FuncAnimation(fig_anim,animate,               #<- this doesn't help
                             init_func=init_graph,
                             frames =100, interval = 50) 

plt.show()
将numpy导入为np
将matplotlib.pyplot作为plt导入
将matplotlib.animation导入为动画
plt.ion()
fig_anim=plt.figure(“动画”)
图,=plt.plot([],[],'-r')
def init_graph():

graph.set_data((lambda_数组),intensity_-shape[5][50][2:)#我认为这是对
anim
的引用的重复,这样运行动画的计时器就不会被垃圾收集。@tcaswell我添加了:
anim=animate_func()
但它仍然不起作用。然后我尝试了
anim=animate.FuncAnimation…..
长调用,但仍然不起作用