我有一个用pandas创建的dataframe,用于生成散点图,并想为该图包含一个回归线。目前我正在尝试使用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
请问有没有人知道我在这里做错了什么?我也不确定如何将回归线添加到我的图表中。如果对我的代码有其他一般性的评论,那将非常赞赏,因为我还是初学者。
regres = polyfit(table1['log2 fold change misson'], table1['log2 fold change'], 1)
@usethedeathstarregres = polyfit(table1 ['log2折变misson'],table1 ['log2折变'],1)
- TimStuart