繁体   English   中英

Matplotlib 实时图出现 0 轴?

[英]Matplotlib live graph appearing with 0 axes?

下面是我必须创建一个从csv文件中读取值的实时更新图的代码。 每次我运行它时,它都会说这个图形是用 0 个轴创建的。 我错过了什么?

def animate(i):
    data = pd.read_csv(tool1path)
    count = range(20)
   
    
    
    plt.cla()
    plt.plot(data,count, label='Jet Height')
 
    plt.legend(loc='upper left')
    plt.tight_layout()
    
ani = FuncAnimation(plt.gcf(), animate, interval=1000)

plt.tight_layout()
plt.show()

尝试以这种方式更改您的代码:

fig, ax = plt.subplots()

def animate(i):
    data = pd.read_csv(tool1path)
    count = range(20)
   
    
    
    plt.cla()
    ax.plot(data,count, label='Jet Height')
 
    ax.legend(loc='upper left')
    plt.tight_layout()
    
ani = FuncAnimation(fig, animate, interval=1000)

plt.tight_layout()
plt.show()

通过这种方式,您可以在调用FuncAnimation之前实例化ax (您在其中 plot 您的数据在animate函数中)和fig (作为参数传递给FuncAnimation )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM