plotting a timeseries graph in python using matplotlib from a csv file

梦想的初衷 提交于 2019-12-06 16:36:23

I'd suggest using pandas:

import pandas as pd
a=pd.read_csv('yourfile.txt',delim_whitespace=True)
for x in a.iterrows():
    x[1][4:].plot(label=str(x[1][0])+str(x[1][1])+str(x[1][2])+str(x[1][3]))

plt.ylim(-1,10)
plt.legend()

I'm not really sure exactly what you want to do but np.loadtxt is the way to go here. make sure to set the delimiter correctly for your file

data = np.loadtxt(fname="test.csv",delimiter=',',skiprows=1)

now the n-th column of data is the n-th column of the file and same for rows.

you can access data by line: data[n] or by column: data[:,n]

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!