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 API to create ridge / joy plots? #1342

Open
maximlt opened this issue May 21, 2024 · 2 comments
Open

Add API to create ridge / joy plots? #1342

maximlt opened this issue May 21, 2024 · 2 comments
Labels
Milestone

Comments

@maximlt
Copy link
Member

maximlt commented May 21, 2024

The subcoordinate_y feature added to HoloViews opens the door to the implementation of ridge / joy plots in hvPlot. I'm opening this issue to gauge the interest in this feature and discuss it.

HoloViews code (stolen from Demetris'!)

import numpy as np
import holoviews as hv
from scipy.stats import gaussian_kde

hv.extension('bokeh')

categories = ['A', 'B', 'C', 'D', 'E']
data = {cat: np.random.normal(loc=i-2, scale=1.0, size=100) for i, cat in enumerate(categories)}
x = np.linspace(-5, 5, 100)

curves = []
areas = []
for i, (cat, values) in enumerate(data.items()):
    pdf = gaussian_kde(values)(x)    
    area = hv.Area((x, pdf), label=cat).opts(
        subcoordinate_y=True, 
        subcoordinate_scale=1.5,
    )
    areas.append(area)

ridge_plot_areas = hv.Overlay(areas).opts(
    width=900,
    height=400,
)

ridge_plot_areas.opts(show_legend=False)

image

Python users can already create such plots using the usual plotting libraries, albeit usually by having to resort to low-level APIs:

I also found two packages implementing high-level APIs:

And a few other packages from other ecosystems:

(#1160 should be implemented first)

@maximlt maximlt added this to the Wishlist milestone May 21, 2024
@droumis
Copy link
Member

droumis commented Jul 9, 2024

Is this theoretical joyplot API separate or the same API as would support a multi-chan timeseries plot? I think they are probably different.

@maximlt
Copy link
Member Author

maximlt commented Jul 23, 2024

Note to self. For a little while I got confused with what exactly a ridgeplot is, trying to adapt it to fit and replace subcoordinate_y. However, a ridgeplot most often is an overlay of kde plots, this is the output this API should offer.

import pandas as pd
import numpy as np
import hvplot.pandas

df = pd.DataFrame(np.random.random((1000, 4)), columns=list("ABCD"))
df.hvplot.ridge()  # somewhat better version of `df.hvplot.kde(subcoordinate_y={'subcoordinate_scale': 2})`

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants