我试图用散点值和回归拟合绘制回归拟合图。
附件是excel文件,包含来自dropbox的数据和所需的输出图(在sigmaplot中制作) https://www.dropbox.com/s/czwq78yyy6vymaj/aniso.xlsx?dl=0
我的代码:
import matplotlib.pyplot as plt
import pandas as pd
data_x = pd.read_excel('aniso.xlsx', 'Sheet1', parse_cols='B', skiprows=2)
data_36 = pd.read_excel('aniso.xlsx', 'Sheet1', parse_cols='H', skiprows=2)
data_37 = pd.read_excel('aniso.xlsx', 'Sheet1', parse_cols='N')
data_38 = pd.read_excel('aniso.xlsx', 'Sheet1', parse_cols='O')
data_39 = pd.read_excel('aniso.xlsx', 'Sheet1', parse_cols='A')
plt.plot(data_x[2:21], data_36[2:21], 'h', color='#1f77b4', label='protein concentration')
plt.plot(data_37, data_38, color='#d62728', ls='--', label='regression fit')
plt.errorbar(data_x[2:21], data_36[2:21], yerr=data_39[2:21])
plt.show()
运行此代码时,出现以下错误:
File "/usr/local/lib/python2.7/site-packages/matplotlib/axes/_axes.py", line 2931, in xywhere
assert len(xs) == len(ys)
AssertionError
答案 0 :(得分:1)
plt.errorbar(x, y)
强烈接受浮点数或类似数组的对象。我会建议:
plt.errorbar(np.array(x), np.array(y))
它对我有用!