Reputation: 29
I am trying to plot a regression fit plot with scatter values and regression fit.
Attached is the excel file with data from dropbox and the desired output graph (made in sigmaplot) https://www.dropbox.com/s/czwq78yyy6vymaj/aniso.xlsx?dl=0
My code:
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()
When running this code, I get the following error:
File "/usr/local/lib/python2.7/site-packages/matplotlib/axes/_axes.py", line 2931, in xywhere
assert len(xs) == len(ys)
AssertionError
Upvotes: 0
Views: 1149
Reputation: 586
plt.errorbar(x, y)
strongly takes float or array-like object. I will suggest:
plt.errorbar(np.array(x), np.array(y))
It worked for me!
Upvotes: 2