【发布时间】:2021-12-13 21:18:48
【问题描述】:
我试图从 scv 文件中读取数据并绘制它们。读取过程很容易工作,但通过绘图完全错过了。 我用 MATLAB 甚至 Excel 都试过了。两者都绘制正确,但在 python 3 中我有问题。似乎是这样。 Plot Photo with python Plot Photo with MATLAB
感谢您的帮助
filename1=fd.askopenfilename(title='open expander text data to graphic ')
reader=csv.reader(filename1)
xpoints = []
ypoints = []
for line in reader:
xpoints.append(line[0])
ypoints.append(line[1])
xpoints_to_graph=np.array(xpoints[])
ypoints_to_graph=np.array(ypoints[])
plt.plot(xpoints_to_graph,ypoints_to_graph)
【问题讨论】:
-
csv.reader将对象 (line[0], line[1]) 作为字符串返回。您需要转换为正确的数据类型,例如ypoints.append(float(line[1]))。也可以考虑import pandas as pd; df=pd.read_csv(filename1) -
另外,请发帖minimal reproducible example。这段代码中有很多损坏的位。
标签: python-3.x matplotlib