Seaborn: swarmplot doesn't recognize `hue` when either the `x` or `y` parameter is omitted

Created on 8 Jun 2016  路  8Comments  路  Source: mwaskom/seaborn

Similar to the example for swarmplot, I would expect the following to color points by the "sex" column:

tips = sns.load_dataset("tips")
ax = sns.swarmplot(y="total_bill", hue="sex", data=tips)

But all points are the same color.

All 8 comments

No, it doesn't, sorry.

This seemed like a bug to me; is this the expected/intended behavior?

If this is the intended behavior, could you help me understand why this happens (so that I can try to figure out how to get the behavior that I want)? Any help would be appreciated.

@izaakm

I ran into this quirk as well and solved it by omitting the data parameter in favor of directly supplying x, y, and hue with one of x, y being populated with dummy data.

# `hue` is ignored
tips = sns.load_dataset("tips")
sns.swarmplot(y="total_bill", hue="sex", data=tips)
plt.show()

image

# `hue` is shown
tips = sns.load_dataset("tips")
sns.swarmplot(y=tips["total_bill"], hue=tips["sex"], x=[""]*len(tips))
plt.show()

image

Yes that will, work, though actually you don't have to omit data; you should be able to mix and match specifying variables with vectors or references to data.

Thanks @greg-pf, nice work-around!

@mwaskom even though you don't consider it to be a bug, would you consider a pull request to fix this?

This is still happening. Any plan to fix it in the future?

No.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alexpetralia picture alexpetralia  路  3Comments

phantom0301 picture phantom0301  路  3Comments

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

sofiatti picture sofiatti  路  4Comments

vinay-jayaram picture vinay-jayaram  路  3Comments