1

I am trying to use residplot on the tips data with hue as below:

tips = sns.load_dataset("tips")
sns.residplot(data=tips, x="total_bill", y="tip", scatter_kws={"hue":"sex"})

I have also tried:

sns.residplot(data=tips, x="total_bill", y="tip", scatter_kws=dict(hue="sex"))

But on both occasions the error message is the same

AttributeError: PathCollection.set() got an unexpected keyword argument 'hue'

I can always manually recreate the residuals with sns.scatterplot() and use hue there

sns.scatterplot(... ,hue="sex")

but was hoping to achieve it in one line.

montoisky
  • 133
  • 1
  • 6
  • As per the documentation, there is not a `hue` parameter. However, this is an `axes` level plot, so you can loop through the categories, and plot them all to the same figure with different colors. Such as with `for ax, (gender, data) in zip(axes, tips.groupby('sex')): ...`. See this [answer](https://stackoverflow.com/a/68793513/7758804) and this [answer](https://stackoverflow.com/a/69228859/7758804). – Trenton McKinney Oct 30 '22 at 19:38
  • 1
    `scatter_kws` refers to [`matplotlib.pyplot.scatter`](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.scatter.html), not [`seaborn.scatterplot`](https://seaborn.pydata.org/generated/seaborn.scatterplot.html), and `plt.scatter` doesn't have `hue=`. – Trenton McKinney Oct 30 '22 at 19:43
  • Thanks Trenton ...that's clear now. – montoisky Oct 30 '22 at 22:21

1 Answers1

-2

Try using lmplot

sns.lmplot(x="total_bill", y="tip", hue="sex", data=tips)
plt.show()
Rodrigo Guzman
  • 487
  • 2
  • 9
  • thanks, but unfortunately that does not work as it plots two regression lines, one for each subset (male, female). – montoisky Nov 02 '22 at 03:33