不同颜色的 Seaborn 回归图 [英] Seaborn regression plot with different colors
问题描述
我想使用 Seaborn 绘制适合我的数据集的线性回归模型.
I want to plot a linear regression model fit for my dataset using Seaborn.
由于该数据集的水柱深度不同(底部、中部和顶部),我希望我的绘图具有 3 种不同的颜色,但线性回归将针对整个数据集.我将这个数据集分开来分别绘制它们,如下所示:
As this data set has different depths in water column (Bottom, Middle and Top), I wanted my plot to have 3 different colors, but the linear regression would be to the overall dataset. I divided this dataset to plot them separately just like the following:
fig, axarr = plt.subplots(3, sharex = True)
axarr[0].scatter(averageOBSB_3min,PumpBotSSC,c='r', label='Bottom')
axarr[0].scatter(averageOBSM_3min,PumpMidSSC,c='g', label='Middle')
axarr[0].scatter(averageOBST_3min,PumpTopSSC,c='b', label='Top')
但这显然不适用于 Seaborn.
But that doesn't work for Seaborn, obviously.
我的问题是:如何在绘图上使用不同的颜色,但对孔数据集进行回归?
My question is: how can I have different colors on the plot, but do the regression for the hole dataset?
推荐答案
混合使用 Seaborn 的 lmplot
和 regplot
:
Use mix of Seaborn's lmplot
and regplot
:
import seaborn as sns
#Use lmplot to plot scatter points
graph = sns.lmplot(x='x_value', y='y_value', hue='water_value', data=df, fit_reg=False)
#Use regplot to plot the regression line for the whole points
sns.regplot(x='x_value', y='y_value', data=df, scatter=False, ax=graph.axes[0, 0]))
这篇关于不同颜色的 Seaborn 回归图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!