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

Align the use of y= argument with error_y in plotly.express #4909

Open
vthemelis opened this issue Nov 27, 2024 · 2 comments
Open

Align the use of y= argument with error_y in plotly.express #4909

vthemelis opened this issue Nov 27, 2024 · 2 comments
Labels
feature something new P3 backlog

Comments

@vthemelis
Copy link

At the moment, I can plot multiple y series with an API that looks like this:

import pandas as pd
import plotly.express as px

data = {
    'X_Values': pd.date_range(start='2023-01-01', periods=10, freq='D'),
    'Y1_Values': [3, 5, 7, 9, 11, 13, 15, 17, 19, 21],
    'Y2_Values': [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],
    'Y3_Values': [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],
}
df = pd.DataFrame(data)

px.scatter(df, x='X_Values', y=['Y1_Values', 'Y2_Values', 'Y3_Values'])

I would expect to be able to provide an array of error bars for each of the y's but that doesn't seem to be the case:

import pandas as pd
import plotly.express as px

data = {
    'X_Values': pd.date_range(start='2023-01-01', periods=10, freq='D'),
    'Y1_Values': [3, 5, 7, 9, 11, 13, 15, 17, 19, 21],
    'Y1_Errors': [0.5, 0.6, 0.7, 0.5, 0.8, 0.5, 0.7, 0.6, 0.5, 0.7],
    'Y2_Values': [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],
    'Y2_Errors': [0.3, 0.5, 0.4, 0.6, 0.7, 0.5, 0.6, 0.4, 0.5, 0.6],
    'Y3_Values': [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],
    'Y3_Errors': [0.4, 0.3, 0.6, 0.5, 0.7, 0.4, 0.5, 0.3, 0.6, 0.5],
}
df = pd.DataFrame(data)

px.scatter(df, x='X_Values', y=['Y1_Values', 'Y2_Values', 'Y3_Values'], error_y=['Y1_Errors', 'Y2_Errors', 'Y3_Errors'])

but this fails with

ValueError: All arguments should have the same length. The length of argument `error_y` is 3, whereas the length of  previously-processed arguments ['X_Values'] is 10

Can this get similar semantics to an array-like object in the y= argument?

@gvwilson gvwilson added P3 backlog feature something new labels Dec 3, 2024
@vthemelis
Copy link
Author

@gvwilson if you think that this feature would be a nice to have I can try to add it myself. I think some of the machinery is already there to make this work with the 'wide_mode' variables.

@gvwilson
Copy link
Contributor

@vthemelis a pull request would be very welcome, and we would try to prioritize review - thank you!

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

No branches or pull requests

2 participants