tpvasconcelos / ridgeplot

Beautiful ridgeline plots in Python
https://ridgeplot.readthedocs.io/
MIT License
65 stars 3 forks source link

[Question] Is it possible to use the library to plot timeseries (non-KDE) data? #170

Closed guidocioni closed 8 months ago

guidocioni commented 8 months ago

I'm trying to understand whether I can reproduce a plot that I made in matplotlib also in plotly. The plot is a ridgeline-like plot but instead of plotting KDEs I'm just representing the evolution of snow depth at a certain station over the winter (for different seasons).

8fdf10ad-d197-40a4-8572-9dd631fb351b

So, the plot has basically the same logic of a ridgeline plot but instead of computing and plotting a KDE I only have to plot the timeseries.

The way I achieved this in matplotlib was to just use subplots and plot in every axis a simple line plot with filled area. I then removed any background and reduced the vertical padding so that the different plots overlap a little bit. All the axes share the same xrange and yrange.

Is this library flexible enough to allow something like that or is that not possible at all? Are you using the violin plot method under the hood?

Thanks :)

tpvasconcelos commented 8 months ago

Hi @guidocioni ! Nice example! 👍

And yes, you can currently do this with the library!

You need to use the (perhaps not very intuitively named) densities parameter. For your use case, you should pass it in a shallow format.

Here's a very basic example:

from ridgeplot import ridgeplot

fig = ridgeplot(
    densities=[
        [(0, 0), (1, 1), (2, 0)], # 2021-2022
        [(1, 0), (2, 1), (3, 0)], # 2022-2023
        [(2, 0), (3, 1), (4, 0)], # 2023-2024
    ],
    labels=["2021-2022", "2022-2023", "2023-2024"],
)
fig.show()
image
guidocioni commented 8 months ago

I'm closing for now, will reopen if I find any issue while doing this :)