【发布时间】:2018-08-21 22:29:20
【问题描述】:
我按照tutorial 的 CSV/TXT 文件的实时图表绘制,但是当我运行 python 程序时,没有创建图表,而是终端进入忙碌模式,直到我使用“Ctrl+Z”退出。
由于某种原因,matplotlib 中的 animate 函数对我不起作用。相反,我编写了以下代码,它应该可以完成这项工作:
import matplotlib.pyplot as plt
while True:
pullData = open("data1.csv","r").read()
dataArray = pullData.split('\n')
xar = []
yar = []
for eachLine in dataArray:
if len(eachLine)>1:
x,y = eachLine.split(',')
xar.append(x)
yar.append(y)
plt.plot(xar, yar)
plt.pause(0.05)
plt.show()
但上面的代码没有正确地从 CSV 文件中读取数据点并生成错误的图表。
我目前在系统上安装了 Python 3.6.5 :: Anaconda, Inc.。请问有人可以帮忙吗?提前谢谢你。
【问题讨论】:
标签: python matplotlib graph