首页 > 解决方案 > 动态动画图表不使用 matlibplot.animation

问题描述

我试图将图表链接到动态保存的 csv,但动画功能似乎不起作用。我的代码如下,谢谢:

    self.f = open("data.csv","r")
    fig,ax1 = plt.subplots()
    ax2 = ax1.twinx()    

    self.data = np.loadtxt(self.f, delimiter = ",", skiprows = 1)
    self.y = self.data[:,5] - self.data[:,6]
    self.z1 = self.data[:,2] - self.data[:,1]        
    c = self.z1.size
    self.t = np.arange(0, c, 1)

    ax1.plot(self.t, self.y,'g-')
    ax2.plot(self.t, self.z1,'b-')

    anim = ani.FuncAnimation(self.fig, self.animate, interval=1000)

    plt.show()


def animate(self,i):
    self.f = open("data.csv","r")
    self.data = np.loadtxt(self.f, delimiter = ",", skiprows = 1)

    self.y = self.data[:,5] - self.data[:,6]
    self.z1 = self.data[:,2] - self.data[:,1]

    c = self.z1.size
    self.t = np.arange(0, c, 1)

标签: pythonpython-3.xanimationmatplotlibcharts

解决方案


推荐阅读