import matplotlib.pyplot as plt
from math import *
f2 = open('C:\\Users\\Audrey\\Documents\\Regress1Par data.txt', 'r')
lines = f2.readlines()
f2.close()
x1 = []
y1 = []
z1 = []
for line in lines:
p = line.split()
x1.append(float(p[0]))
y1.append(float(p[1]))
z1.append(float(p[2]))
plt.scatter(x1, y1)
yerr=z1
plt.errorbar(x1,y1,yerr=yerr, fmt='o')
plt.plot(2.53+9.33(x) for x in x1)
plt.show()
我收到错误"输入错误:'浮动'对象不可调用" 如何用x1绘制这一行呢?
答案 0 :(得分:0)
问题是你在这里缺少一个操作员:
plt.plot(2.53+9.33(x) for x in x1)
您需要使用
plt.plot(2.53+9.33*(x) for x in x1)
因为9.33()不是可调用函数:
>>> 2.59+9.33(x)
Traceback (most recent call last):
File "<pyshell#24>", line 1, in <module>
2.59+9.33(x)
TypeError: 'float' object is not callable