Skip to content

Fix px error bars ignoring opacity on categorical traces - #5781

Open
00200200 wants to merge 1 commit into
plotly:mainfrom
00200200:4353-error-bar-opacity
Open

00200200 wants to merge 1 commit into
plotly:mainfrom
00200200:4353-error-bar-opacity

Conversation

@00200200

Copy link
Copy Markdown

Link to issue

Closes #4353

Description of change

Plotly.js error bars have a color property but no opacity, so px.scatter(..., color=..., opacity=0.6, error_y=...) faded the markers and left the error bars fully opaque.

For categorically colored traces (one marker color per trace), this now copies that color onto error_x / error_y / error_z as an rgba(...) string that includes the requested opacity.

Continuous color still cannot follow per-point marker colors: error_y.color is a single color in the schema, not an array. That path is unchanged and covered so opacity no longer has to special-case it.

Demo

import plotly.express as px

df = px.data.iris()
df["e_plus"] = df["sepal_width"] / 100
df["e_minus"] = df["sepal_width"] / 40
fig = px.scatter(
    df, x="sepal_width", y="sepal_length", color="species",
    error_y="e_plus", error_y_minus="e_minus", opacity=0.6,
)
print(fig.data[0].marker.opacity, fig.data[0].error_y.color)
# 0.6 rgba(99, 110, 250, 0.6)

Testing strategy

Added unit tests in tests/test_optional/test_px/test_px.py for categorical error_y + opacity, categorical error_x + opacity, the no-opacity inheritance path, and continuous color + opacity.

Guidelines

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error bars in px.scatter should inherit color and opacity from markers by default

2 participants