Seaborn: KDE, pandas, and hue

Created on 11 Jun 2015  路  3Comments  路  Source: mwaskom/seaborn

Coming from R and ggplot(), I have repeatedly found myself wanting to write this:

sns.kdeplot(data = DateFrame, x = 'column1', hue = 'column2')

expecting to get something like one of these.

And then I look through the docs to see what I actually have to do to get a plot that looks like that and it seems very cumbersome. Not at all what I would want from a quick-plot/data-exploration tool.

Is this a syntax that you would be interested in supporting or is there something deeply un-seaborn about it?

question

Most helpful comment

Yes something like this will probably happen, depending on how upset people get about the changes to the categorical plots in 0.6.

In addition to Tom's code, you could also do

sns.FacetGrid(data, hue="column2").map(sns.kdeplot, "column1")

Which is kind of even more ggplotty.

All 3 comments

@TDaltonC FYI I'll typically do something like

gr = df.groupby('column2').column1
for label, arr in gr:
    sns.kdeplot(arr, label=label, shade=True

which isn't too bad.

Yes something like this will probably happen, depending on how upset people get about the changes to the categorical plots in 0.6.

In addition to Tom's code, you could also do

sns.FacetGrid(data, hue="column2").map(sns.kdeplot, "column1")

Which is kind of even more ggplotty.

Closed in #2104 with the addition of hue to kdeplot

Was this page helpful?
0 / 5 - 0 ratings

Related issues

amelio-vazquez-reina picture amelio-vazquez-reina  路  3Comments

alexpetralia picture alexpetralia  路  3Comments

bondarevts picture bondarevts  路  3Comments

tritemio picture tritemio  路  3Comments

sofiatti picture sofiatti  路  4Comments