Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add split violin #4112

Merged
merged 10 commits into from
Jan 13, 2020
Merged

Add split violin #4112

merged 10 commits into from
Jan 13, 2020

Conversation

ahuang11
Copy link
Collaborator

@ahuang11 ahuang11 commented Nov 29, 2019

#4096
Not ready yet. I don't know how to add a legend and change the colors. Not sure if this implementation is the best approach. Also, not sure how to make the widths as proportionate as seaborn. Feel free to edit/make commits directly. Also didn't handle for matplotlib/plotly.

import numpy as np
import holoviews as hv
hv.extension('bokeh')

import seaborn as sns
sns.set(style="whitegrid")
tips = sns.load_dataset("tips")

ax = sns.violinplot(x="day", y="total_bill", hue="sex",
                    data=tips, palette="Set2", split=True,
                    scale="count")

import pandas as pd
tips = pd.concat([
    tips.loc[tips['day'] == 'Thur'],
    tips.loc[tips['day'] == 'Fri'],
    tips.loc[tips['day'] == 'Sat'],
    tips.loc[tips['day'] == 'Sun']
])

hv.Violin(tips, 'day', ['total_bill', 'sex']).opts(ylim=(-10, 60), width=600)

image

@philippjfr
Copy link
Member

Thanks for having a go at this, sadly as I said above this design doesn't really fit in with the rest of HoloViews.

@ahuang11
Copy link
Collaborator Author

ahuang11 commented Nov 29, 2019

No worries. I was basing it off this idea:
hv.Area((X, Y, Y2), vdims=['y', 'y2']) * hv.Area((X, Y, Y3), vdims=['y', 'y3'])
image

and I think I tried kdims first, but it created groups like:
hv.Violin(tips, ['day', 'sex'], ['total_bill']).opts(ylim=(-10, 60), width=600)
image

Any suggestions on how to deal with this group vs split violin? The closest I think is like stacked bar chart?

@ahuang11
Copy link
Collaborator Author

ahuang11 commented Nov 30, 2019

Okay, I swapped vdims for kdims. Still not sure how to add coloring/legend.
image

When I try:

        # if split_key is not None:
        #     legend_prop = 'legend_field' if bokeh_version >= '1.3.5' else 'legend'
        #     kde_map[legend_prop] = split_key

It says the legend must be a string

@philippjfr
Copy link
Member

Thanks, I'll take a look at coloring and legend. Instead of split=True/False I think it should accept a dim mapping.

@philippjfr
Copy link
Member

Initial attempt, still needs some cleanup:

Screen Shot 2020-01-13 at 5 43 52 PM

@philippjfr
Copy link
Member

Added a gallery example:

bokeh_plot - 2020-01-13T184317 102

@ahuang11
Copy link
Collaborator Author

Really excited for this!

@philippjfr philippjfr merged commit 0519262 into master Jan 13, 2020
@jbednar jbednar changed the title Add split violin partially Add split violin Jan 13, 2020
@ccneko
Copy link

ccneko commented Dec 28, 2020

Thanks for the really nice functionality. By the way, any chance of Plotly support? (Looking at Panel to use both Bokeh & Plotly meanwhile)

@ahuang11
Copy link
Collaborator Author

I don't think so, but maybe you can open a new issue for split violin plots in plotly.

@ccneko
Copy link

ccneko commented Dec 30, 2020

@ahuang11 Thanks for confirming. I will directly use the Plotly split violin plots first for the current usage.

@philippjfr philippjfr deleted the split_violin branch April 25, 2022 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants