Repository navigation
Fix px opacity values misaligned when points are split into traces - #5825
Open
shivenaggarwal wants to merge 1 commit into
Open
shivenaggarwal wants to merge 1 commit into
shivenaggarwal wants to merge 1 commit into
Conversation
When `opacity` was given one value per point, Plotly Express passed the whole array to every trace, so once points were split by color, symbol, facets or animation frames the values no longer matched their markers. A non-numeric `opacity` is now handled like the other data arguments: it is added to the data frame, split along with the rest of the data and set as `marker.opacity` on each trace. This also makes column names work. A number still applies to all marks, as before.
shivenaggarwal
force-pushed
the
px-opacity-per-trace
branch
from
October 18, 2026 06:09
244d3fb to
ba24e66
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to issue
Closes #4580
Description of change
Passing one
opacityvalue per point to a Plotly Express function works for a single trace. Once the points are split into several traces (bycolor,symbol, facets, animation frames and so on), the whole array is copied intomarker.opacityof every trace, so the values no longer match their markers. The length isn't checked either. The cause is thatopacitygoes into the shared trace patch as is, instead of going through the data frame likesizeortext.A non-numeric
opacityis now handled like the other data arguments.build_dataframeadds it as a column, so it is split with the rest of the data, andmake_trace_kwargssets each trace'smarker.opacityfrom that trace's own rows. Column names now work too, and a list of the wrong length raises the usual "All arguments should have the same length" error. A number is still applied to all marks, as before. That includes NumPy scalars, and1when a column is named1.Demo
px.scatter(df, x="x", y="y", facet_col="f", opacity="alpha")used to raiseInvalid value of type 'builtins.str' received for the 'opacity' property of scatter.marker. It now sets each facet's opacities from thealphacolumn.Testing strategy
Added tests to
tests/test_optional/test_px/test_px.py. They run with every dataframe backend:color, forpx.scatter,px.barandpx.scatter_matrixfacet_rowandfacet_col0.5;1with an integer column named1; a NumPy float) that is still set as a single value on every traceThe first two fail on
main.pytest tests/test_optional/test_pxpasses locally.Additional information (optional)
pie,funnel,funnel_area,density_mapandscatter_3d) still reject per-point values through the same property validation as before, though the message now shows the generated column name rather than the list. I can add an explicit error for these if you prefer.px.histogramstill passes the values tomarker.opacity, and plotly.js applies them per bin, as onmain.opacitydocstring as "float". I'm happy to document per-point values if you'd like them to be part of the public API.args["opacity"]can be a column name. This matters for Fix px error bars ignoring opacity on categorical traces #5781, which builds anrgba()color from that value.Guidelines