Plot density/proportion histograms with hue parameter in seaborn jointplot?

351 Views Asked by At

Is there a way to specify both hue and have the marginal histograms be plotted with stat=density ? It seems I can have one or the other -- it will graph either without the hue kwa or without stat='density', but it errors out when I include both parameters.

Here is some example code:

penguins=sns.load_dataset('penguins')
sns.jointplot(data=penguins, x="bill_length_mm", y="bill_depth_mm", hue='species',marginal_kws=dict(color='r',stat='density'))

And here is the error:

`---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-15-e8d515eeeab0> in <module>
----> 1 sns.jointplot(data=penguins, x="bill_length_mm", y="bill_depth_mm", hue='species',marginal_kws=dict(color='r',stat='density'))

12 frames
/usr/local/lib/python3.8/dist-packages/matplotlib/artist.py in _update_property(self, k, v)
    999                 func = getattr(self, 'set_' + k, None)
   1000                 if not callable(func):
-> 1001                     raise AttributeError('{!r} object has no property {!r}'
   1002                                          .format(type(self).__name__, k))
   1003                 return func(v)

AttributeError: 'PolyCollection' object has no property 'stat'`

Thanks!

I can get a jointplot with two colors which are designated by a categorical value in my dataframe. However, I would like for the marginal histograms to be plotted by density as specified in histplot but not absolute value, because one of the categories has many more entries than the other. I cannot get both hue and stat=density without the code erroring out as above.

0

There are 0 best solutions below