【发布时间】:2014-06-02 20:46:28
【问题描述】:
我是 python 和 matplotlib 语言的新手,正在为我丈夫做一些事情。
希望大家能帮帮我。
我想使用 Open 拉入一个文件,读取它,并用它的值更新一个图表。
听起来很简单吧?在实践中并没有那么多。
这是我到目前为止打开文件并绘制图表的内容。这可以正常工作,因为它可以将文件绘制 1 次。
import matplotlib.pyplot as plt
fileopen = open('.../plotresults.txt', 'r').read()
fileopen = eval(fileopen) ##because the file contains a dict and security is not an issue.
print(fileopen) ## So I can see it working
for key,value in fileopen.items():
plot1 = value
plt.plot(plot1, label=str(key))
plt.legend()
plt.show()
现在我想为图表制作动画或更新它,以便我可以看到数据的变化。我曾尝试使用 matplotlib 的动画功能,但它超出了我目前的知识范围。
有没有一种简单的方法来更新这个图表,比如每 5 分钟一次?
注意: 我尝试使用 Schedule,但它破坏了程序(可能是 schedule 和 matplotlib 图形打开之间的冲突??)。
任何帮助将不胜感激。
【问题讨论】:
标签: python-3.x matplotlib