Seaborn中没有线性拟合的散点图 [英] Scatterplot without linear fit in seaborn

查看:29
本文介绍了Seaborn中没有线性拟合的散点图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种方法可以关闭seaborn的 lmplot 中的线性拟合,或者是否有一个等效函数只是生成散点图.当然,我也可以使用matplotlib,但是,我发现seaborn的语法和美学非常吸引人.例如,.我想绘制以下情节

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

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')

推荐答案

set fit_reg 参数为 False:

sns.lmplot("x", "y", data=df, hue='dataset', fit_reg=False)

这篇关于Seaborn中没有线性拟合的散点图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆