Seaborn: lmplot hue variable with single regression line

Created on 10 Feb 2015  Â·  3Comments  Â·  Source: mwaskom/seaborn

I'd like to color with different hues the different points on the graph, but retain a single regression line.
At the moment setting hue='foo' in an lmplot draws a differrent regression line for every hue, whils i would like to retain a single one(the one you get if you don't set hue) but color the points. is it possible ?

question

Most helpful comment

From lmplot's perspective (actually from FacetGrid's) the scatterplot and regression line are considered one item, but you could do something like this:

g = sns.lmplot(x="x", y="y", hue="g", data=df, fit_reg=False)
sns.regplot(x="x", y="y", data=df, scatter=False, ax=g.axes[0, 0])

This won't work with multiple column or row facets.

All 3 comments

From lmplot's perspective (actually from FacetGrid's) the scatterplot and regression line are considered one item, but you could do something like this:

g = sns.lmplot(x="x", y="y", hue="g", data=df, fit_reg=False)
sns.regplot(x="x", y="y", data=df, scatter=False, ax=g.axes[0, 0])

This won't work with multiple column or row facets.

Thanks, that's really what I was looking for. I've just used a for loop on
the variable I'd have set as col to to get around the lack of it, not as
nice but works none the less, thanks a lot

Lorenzo

On Tue, Feb 10, 2015 at 5:18 PM, Michael Waskom [email protected]
wrote:

From lmplot's perspective (actually from FacetGrid's) the scatterplot and
regression line are considered one item, but you could do something like
this:

g = sns.lmplot(x="x", y="y", hue="g", data=df, fit_reg=False)
sns.regplot(x="x", y="y", data=df, scatter=False, ax=g.axes[0, 0])

This won't work with multiple column or row facets.

—
Reply to this email directly or view it on GitHub
https://github.com/mwaskom/seaborn/issues/443#issuecomment-73729039.

I also used this way to generate regression plot with two colors. However, the figure size is unable to be adjusted for some reason. It remains small even when I keep increasing the figure size via "plt.figure(figsize=(20,20))". Every time, when the figure is generated, this figure size message is also printed: "

". The number "1440x1440" change when the figure size is changed but not the figure itself.. I set the figure size before I do both sns.lmplot and sns.reglot. Does anyone know why?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bondarevts picture bondarevts  Â·  3Comments

ConstantinoSchillebeeckx picture ConstantinoSchillebeeckx  Â·  4Comments

queryous picture queryous  Â·  4Comments

amelio-vazquez-reina picture amelio-vazquez-reina  Â·  4Comments

dkoppstein picture dkoppstein  Â·  4Comments