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

Invert the plot axis #311

Open
gioxc88 opened this issue Jan 30, 2025 · 9 comments
Open

Invert the plot axis #311

gioxc88 opened this issue Jan 30, 2025 · 9 comments
Labels
enhancement New feature or request

Comments

@gioxc88
Copy link

gioxc88 commented Jan 30, 2025

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

Copy link

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
Copy link
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
Copy link
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

@tpvasconcelos tpvasconcelos added the enhancement New feature or request label Jan 31, 2025
@gioxc88
Copy link
Author

gioxc88 commented Jan 31, 2025

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
Copy link
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
Copy link
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
Copy link
Author

gioxc88 commented Feb 3, 2025

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
Copy link
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
Copy link
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
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants