对于一些学校作业,我一直试图让pyplot根据来自Logger Pro的数据为我绘制一些科学图。我遇到了错误
ValueError: could not convert string to float: '0'这是该计划:
plot.py
-------------------------------
import matplotlib.pyplot as plt
import numpy as np
infile = open('text', 'r')
xs = []
ys = []
for line in infile:
print (type(line))
x, y = line.split()
# print (x, y)
# print (type(line), type(x), type(y))
xs.append(float(x))
ys.append(float(y))
xs.sort()
ys.sort()
plt.plot(xs, ys, 'bo')
plt.grid(True)
# print (xs, ys)
plt.show()
infile.close()输入文件包含以下内容:
text
-------------------------------
0 1.33
1 1.37
2 1.43
3 1.51
4 1.59
5 1.67
6 1.77
7 1.86
8 1.98
9 2.1这是我在运行程序时收到的错误消息:
Traceback (most recent call last):
File "\route\to\the\file\plot01.py", line 36, in
xs.append(float(x))
ValueError: could not convert string to float: '0'