Repository navigation
Opacity and color not working together in px.scatter #4580
Copy link
Copy link
Open
Labels
P3backlogbacklogbugsomething brokensomething brokensev-3annoyance with workaroundannoyance with workaround
Description
I am creating a plot, which has color and opacity together. When I use color, the opacity doesn't work correctly. Here is a reproducible example:
a = [0.067, 2.159, 0.253, 4.72, 0.614, 4.929, 5.647, 1.624, 0.946, 5.408, 0.308, 0.765, 0.006, 0.326, 4.201, 5.976, 1.644, 4.7, 5.67, 5.002, 5.208, 5.658, 6.821, 6.081, 2.687, 3.106, 0.207, 6.139, 0.242, 4.214, 3.975, 4.639, 5.744, 1.725, 5.753, 7.863, 1.67, 4.466, 5.283, 4.683, 0.764, 5.408, 5.279, 1.088, 0.874, 4.72, 5.39, 0.514, 0.023, 0.196, 2.781, 5.317, 5.262, 4.576, 4.683, 6.437, 6.614, 2.27, 2.92, 2.812, 6.383, 0.486, 6.082, 0.791, 0.283, 0.047, 4.671, 3.362, 0.314, 3.294, 0.134, 3.662, 6.025, 7.097, 2.089, 0.019, 1.058, 6.095, 2.436, 0.563, 5.096, 6.824, 1.707, 1.621, 6.058, 5.621, 0.956, 2.673, 5.751, 3.286, 0.809, 4.468, 6.026, 0.089, 0.29, 5.556, 4.81, 4.811, 5.08, 4.671, 4.614, 6.417, 4.9, 3.398, 6.091, 6.511, 6.46, 5.596, 6.4, 7.219, 5.474, 5.541, 5.542, 5.014, 1.853, 2.726, 4.681, 0.985, 0.114, 0.171, 4.494, 3.783, 0.501, 4.531, 4.424, 5.573, 5.757, 4.991, 5.715, 5.54, 5.127, 4.327, 5.125, 5.545, 4.397, 5.174, 2.417, 2.209, 4.774, 0.095, 0.577, 1.149, 5.158, 1.338, 3.482, 5.143, 0.849, 0.214, 0.113, 3.696, 4.432, 4.29, 4.507, 5.24, 4.158, 4.494, 0.0, 0.851, 5.578, 1.604, 4.856, 4.424, 2.316, 0.259, 1.39, 3.12, 0.446, 1.017, 2.179, 0.017, 3.438, 3.665, 0.538, 1.732, 5.781, 0.241, 0.21, 4.779, 4.519, 0.507, 0.295, 0.956, 5.641, 5.118, 0.9, 4.499, 5.07, 2.568, 1.089, 6.174, 4.45, 0.863, 1.943, 3.451, 3.276, 0.026, 1.378]
b = [int(bool(i<=2)) for i in a]
c = ['r', 'r', 'r', 'r', 'r', 'b', 'b', 'r', 'r', 'r', 'r', 'b', 'r', 'r', 'b', 'r', 'b', 'b', 'b', 'b', 'r', 'b', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'b', 'r', 'r', 'b', 'r', 'r', 'r', 'b', 'b', 'r', 'r', 'b', 'r', 'r', 'b', 'b', 'r', 'r', 'r', 'r', 'b', 'b', 'b', 'r', 'r', 'b', 'r', 'r', 'b', 'r', 'r', 'b', 'r', 'b', 'r', 'r', 'r', 'b', 'b', 'r', 'r', 'r', 'r', 'r', 'r', 'b', 'b', 'b', 'r', 'r', 'b', 'b', 'r', 'b', 'b', 'r', 'r', 'b', 'r', 'r', 'r', 'r', 'r', 'r', 'b', 'r', 'b', 'b', 'b', 'r', 'r', 'r', 'r', 'r', 'r', 'b', 'b', 'b', 'b', 'b', 'b', 'r', 'b', 'r', 'r', 'b', 'r', 'r', 'b', 'b', 'r', 'r', 'r', 'b', 'b', 'r', 'r', 'b', 'b', 'b', 'r', 'r', 'r', 'r', 'r', 'b', 'r', 'r', 'r', 'r', 'r', 'b', 'r', 'r', 'r', 'r', 'b', 'r', 'r', 'r', 'r', 'b', 'b', 'r', 'r', 'r', 'r', 'r', 'b', 'b', 'r', 'r', 'r', 'r', 'b', 'b', 'b', 'b', 'b', 'r', 'b', 'b', 'b', 'r', 'r', 'r', 'r', 'b', 'r', 'r', 'r', 'b', 'r', 'r', 'b', 'b', 'b', 'r', 'r', 'b', 'r', 'b', 'b', 'r', 'r', 'r', 'b']
when I use:
fig = px.scatter(y=a,opacity=b,text=['x']*197)
fig.show()
I get this image, which is correct (anything below 2 has an opacity of 1)

but when I use both color and opacity, it gets messed up:
fig = px.scatter(y=a,opacity=b,color=c,text=['x']*197)
fig.show()
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P3backlogbacklogbugsomething brokensomething brokensev-3annoyance with workaroundannoyance with workaround

Activity
Coding-with-Adam commentedon Apr 19, 2024
Thank you for reporting @NooraAz
emilykl commentedon Sep 2, 2026
@NooraAz Thank you for the report, and apologies that this issue never got a timely reply!
This is indeed a bug; the issue is that the
opacityargument accepts a list or colname without complaining, and applies it correctly to a plot where points are not split by color, but in the case where points are split by color, theopacitylist is applied naively to each individual trace (red and blue) without being split, so the values are completely misaligned.At the very least, we should reject providing a list or colname to
opacitywhen splitting by color or faceting.Ideally, we should correctly split and apply the list to each color such that the correct opacity values are aligned with the correct points. I looked into it a bit and it's probably doable but a little complex due to some quirks in the
pxmachinery.