Python seaborn 中没有线性拟合的散点图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29637150/
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
Scatterplot without linear fit in seaborn
提问by
I am wondering if there is a way to turn off the linear fit in seaborn's lmplot
or if there is an equivalent function that just produces the scatterplot.
Sure, I could also use matplotlib, however, I find the syntax and aesthetics in seaborn quite appealing. E.g,. I want to plot the following plot
我想知道是否有办法关闭 seaborn 中的线性拟合,lmplot
或者是否有一个等效的函数可以生成散点图。当然,我也可以使用 matplotlib,但是,我发现 seaborn 中的语法和美学非常吸引人。例如,。我想绘制以下情节
import seaborn as sns
sns.set(style="ticks")
df = sns.load_dataset("anscombe")
sns.lmplot("x", "y", data=df, hue='dataset')
Without the linear fit like so:
没有像这样的线性拟合:
from itertools import cycle
import numpy as np
import matplotlib.pyplot as plt
color_gen = cycle(('blue', 'lightgreen', 'red', 'purple', 'gray', 'cyan'))
for lab in np.unique(df['dataset']):
plt.scatter(df.loc[df['dataset'] == lab, 'x'],
df.loc[df['dataset'] == lab, 'y'],
c=next(color_gen),
label=lab)
plt.legend(loc='best')
采纳答案by HYRY
set fit_reg
argument to False
:
将fit_reg
参数设置为False
:
sns.lmplot("x", "y", data=df, hue='dataset', fit_reg=False)
回答by Michael Hall
This doesn't directly answer the question, but may help others who find there way here who just want to do a plain old scatter plot.
As of version 0.9.0seaborn now has a scatterplot
method.
这并不能直接回答问题,但可能会帮助其他人在这里找到方法,他们只想做一个简单的旧散点图。
从 0.9.0 版本开始,seaborn 现在有一个scatterplot
方法。
import seaborn as sns
sns.set(style="ticks")
df = sns.load_dataset("anscombe")
sns.scatterplot("x", "y", data=df, hue='dataset')
回答by Rudra Mohan
I recommend instead of sns.lmplot()
to use sns.scatterplot()
我建议而不是sns.lmplot()
使用sns.scatterplot()
# import libaries
import seaborn as sns
# load tips dataset from GitHub seaborn repository
tips_df = sns.load_dataset("tips")
#create scatter plot
sns.scatterplot(x = "tip", y = "total_bill", data = tips_df, hue ="sex")
To learn more in detail follow seaborn scatter plotusing sns.scatterplot() tutorial
要详细了解使用 sns.scatterplot() 教程的seaborn 散点图