我在 pandas 中有一个数据框,我用它来生成散点图,并希望在图中包含一条回归线。现在我正在尝试用 polyfit 来做到这一点。
这是我的代码:
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
from numpy import *
table1 = pd.DataFrame.from_csv('upregulated_genes.txt', sep='\t', header=0, index_col=0)
table2 = pd.DataFrame.from_csv('misson_genes.txt', sep='\t', header=0, index_col=0)
table1 = table1.join(table2, how='outer')
table1 = table1.dropna(how='any')
table1 = table1.replace('#DIV/0!', 0)
# scatterplot
plt.scatter(table1['log2 fold change misson'], table1['log2 fold change'])
plt.ylabel('log2 expression fold change')
plt.xlabel('log2 expression fold change Misson et al. 2005')
plt.title('Root Early Upregulated Genes')
plt.axis([0,12,-5,12])
# this is the part I'm unsure about
regres = polyfit(table1['log2 fold change misson'], table1['log2 fold change'], 1)
plt.show()
但我收到以下错误:
TypeError: cannot concatenate 'str' and 'float' objects
有谁知道我要去哪里错了?我也不确定如何将回归线添加到我的情节中。对我的代码的任何其他一般性评论也将不胜感激,我仍然是初学者。