Skip to content

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

Open
@vthemelis

Description

@vthemelis

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3backlogfeaturesomething new

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions