plotly / plotly/plotly.py

Opacity and color not working together in px.scatter

Open
#4,580 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P3 sev-3
Dominant language
Python
Stars
18.8k
Forks
2.8k
Avg merge
16h 26m
Merged PRs (30d)
21

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)
newplot - 2024-04-18T185902 940

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()

newplot - 2024-04-18T190041 205

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the px.scatter examples in the issue and run both versions: opacity alone, then opacity combined with color. Compare the generated plot behavior for points below 2 and verify that adding color does not change the supplied opacity values. Done means the reproducible example renders both color and opacity correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
plotly, python
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.