Align the use of `y=` argument with `error_y` in `plotly.express`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 18.8k
- Forks
- 2.8k
- Avg merge
- 16h 26m
- Merged PRs (30d)
- 21
Description
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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the examples with plotly.express.scatter, beginning with the handling of the y and error_y arguments. Compare how array-like y values are expanded with how error_y is validated. Done means matching error arrays can be supplied for each y series without the reported length error, with relevant behavior covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data-visualization
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100