Skip to content

Invert the plot axis #311

Open
Open
@gioxc88

Description

@gioxc88

Hi,
Thanks for this great package.

Is it possible to do in a way such that the density is on the y axis and the labels are on the x axis ?

That would pair well with time series plots
Thanks

Activity

github-actions

github-actions commented on Jan 30, 2025

@github-actions

Thank you for submitting your first issue with us! 🎉

Our response times may vary, but we'll get back to you as soon as we can!

Welcome aboard! 🚀

tpvasconcelos

tpvasconcelos commented on Jan 31, 2025

@tpvasconcelos
Owner

Hey, Glad you're finding it useful!

I've thought about this before but never got around to seeing how easy/complex it would be to implement. The problem with such features is that they can significantly increase the complexity of the project while not adding value to most users. That said, I'll try to take a look at it. (let me know if you're interested in contributing btw)

To be sure we're talking about the same thing, this is what your mean, right?
Image

If not, please share some examples.

tpvasconcelos

tpvasconcelos commented on Jan 31, 2025

@tpvasconcelos
Owner

A lot of people have shows interest (myself include) in using this package for representing probabilistic forecasts. Perhaps more users would find this feature helpful for this reason.

I was also thinking about adding some helper functionality to display some summary statistics such as tracking quantiles or mean. Something similar to the following plot (although I'm not sure which statistic they're plotting here 🤔):

Image

gioxc88

gioxc88 commented on Jan 31, 2025

@gioxc88
Author

Hey, Glad you're finding it useful!

I've thought about this before but never got around to seeing how easy/complex it would be to implement. The problem with such features is that they can significantly increase the complexity of the project while not adding value to most users. That said, I'll try to take a look at it. (let me know if you're interested in contributing btw)

To be sure we're talking about the same thing, this is what your mean, right?
Image

If not, please share some examples.

Thanks a lot for the reply!
Yes this is exactly what I am talking about.

I think I managed to do it by passing the data as y= instead of x= to the go.Violin and then doing a fig.update_traces(orientation='v')

I didn't play around with spacing yet (making the various densities overlap which looks better)

I think this would be a great feature to add and also regarding your second point (adding mean and maybe +/- std) that would be also useful (I am doing it myself externally anyway) because I want to visually keep track of the mean shift over time.

Thanks a lot !

tpvasconcelos

tpvasconcelos commented on Feb 1, 2025

@tpvasconcelos
Owner

I think this would be a great feature to add and also regarding your second point (adding mean and maybe +/- std) that would be also useful (I am doing it myself externally anyway) because I want to visually keep track of the mean shift over time.

Could you share an example plot from your implementation? It could be a nice reference for me to use when implementing it on this project. If you're using this for work, feel free too use some dummy data instead ofc 👍

tpvasconcelos

tpvasconcelos commented on Feb 1, 2025

@tpvasconcelos
Owner

I think I managed to do it by passing the data as y= instead of x= to the go.Violin and then doing a fig.update_traces(orientation='v')

Yes indeed that is also an option, although less configurable. Did you also have to set a side option (e.g. side="positive") somewhere to get Plotly to plot only half of the violin's KDE?

gioxc88

gioxc88 commented on Feb 3, 2025

@gioxc88
Author
import plotly.graph_objects as go
from plotly.colors import n_colors
import numpy as np

n_scen = 100
time_steps = 4
data = np.random.normal(size=(time_steps, n_scen))

colors = n_colors('rgb(5, 200, 200)', 'rgb(200, 10, 10)', data.shape[0], colortype='rgb')
fig = go.Figure()
for data_line, color in zip(data, colors):
      fig.add_trace(go.Violin(y=data_line, line_color=color))

fig.update_traces(orientation='v', side='positive', width=1, points=False)
fig.update_layout(xaxis_showgrid=False, xaxis_zeroline=False)
Image
tpvasconcelos

tpvasconcelos commented on Feb 3, 2025

@tpvasconcelos
Owner

@gioxc88 Many thanks! (FYI: I updated your comment to include the graph output, which can be useful for other users looking for a similar solution)

tpvasconcelos

tpvasconcelos commented on Feb 3, 2025

@tpvasconcelos
Owner

For reference, I'm not against this feature. I think it could be a really nice addition to the project. I'm only wary of the complexity this would add to the codebase. One thing to consider here is that we also support plotting histograms (or, more generically, bar charts) instead of KDE/area plots. Actually, we support using both trace types on the same figure. This would need to be considered when implementing this feature.

If someone wants to work on this, I'm open to review proposals and pull-requests 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @tpvasconcelos@gioxc88

        Issue actions

          Invert the plot axis · Issue #311 · tpvasconcelos/ridgeplot