mwaskom / seaborn

Statistical data visualization in Python
https://seaborn.pydata.org
BSD 3-Clause "New" or "Revised" License
12.44k stars 1.91k forks source link

Feature requests: Asymmetric swarmplot function #3554

Open sunroofgod opened 10 months ago

sunroofgod commented 10 months ago

Hi!

I wanted to check how open the seaborn team would be to adding an additional param to the swarmplot() function to plot asymmetric swarmplots as well.

For example, users could potentially call

  1. with a new param side: "r" | "l" | "c", which represents the sides "right", "left", "center" respectively that the swarm plot would be aligned against. ("center" would be the same as how the swarmplots are currently being plotted)
    
    import seaborn as sns

tips = sns.load_dataset("tips") sns.swarmplot(data=tips, x="day", y="total_bill", hue="day", legend=False, side="right")


2. perhaps in more alignment with the API of the current `violinplot()` function, a new param `split` instead could be used to reproduce the same plot as the one above. 

```python
sns.swarmplot(data=tips, x="day", y="total_bill", hue="day", legend=False, split=True)

Both of which would result in the following plot below:

swarmplot_side= right

(The plot above has been produced via code edits I've made to the current swarmplot() function wrt point 1.)

To sum it up,

Thank you so much!

mwaskom commented 10 months ago

I think this poses some tricky API issues.

1) Several of the categorical functions produce asymmetrical plots that might make sense to draw "half" of this way. Would adding this just to swarmplot introduce new API inconsistencies?

2) While you mention that violinplot has a similar feature, it's not identical: a single split violin (as of v0.13.0 where this became possible) spans the entire width of the space allotted for a non-split violin. Maybe that is actually not ideal and it would be better for odd splits to occupy half the space, but that does mean that just adding split to swarmplot to make the plot you're showing above doesn't make much sense.

3) What happens with hue is used? Would you have multiple colors on swarms with the shapes your'e showing above? People would probably want, if not expect, that the swarm might "split" the way the violin plot does (they certainly would if the split parameter is used).

sunroofgod commented 9 months ago

Hi, thank you so much for the reply! Will look into the concerns you've brought up and get back to you again once we have something more substantial.