我可以使用带有 Pandas 数据框的散点图绘制回归线并显示参数吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36420908/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can I draw a regression line and show parameters using scatterplot with a pandas dataframe?
提问by Markus W
I would like to produce a Scatterplot from a Pandas dataframe using the following code:
我想使用以下代码从 Pandas 数据帧生成散点图:
df.plot.scatter(x='one', y='two, title='Scatterplot')
Is there a Parameter I can send with the Statement, so it plots a Regression line and shows the Parameters of the fit?
是否有我可以与 Statement 一起发送的参数,因此它绘制了一条回归线并显示了拟合的参数?
something like:
就像是:
df.plot.scatter(x='one', y='two', title='Scatterplot', Regression_line)
回答by Pascal dB
I don't think that there's such a paramter for DataFrame.plot(). However, you can easily achieve this using Seaborn. Just pass the pandas dataframe to lmplot(assuming you have seaborn installed):
我不认为 DataFrame.plot() 有这样的参数。但是,您可以使用Seaborn轻松实现这一点。只需将Pandas数据框传递给lmplot(假设您安装了 seaborn):
import seaborn as sns
sns.lmplot(x='one',y='two',data=df,fit_reg=True)