Can not use transparency in px.imshow
Open
Nobody has claimed this yet.
bug
P3
- Dominant language
- Python
- Stars
- 18.8k
- Forks
- 2.8k
- Avg merge
- 16h 26m
- Merged PRs (30d)
- 21
Description
I am using plotly 4.12.0.
The px.imshow function has this example in the docs:
import plotly.express as px
import numpy as np
img_rgb = np.array([[[255, 0, 0], [0, 255, 0], [0, 0, 255]],
[[0, 255, 0], [0, 0, 255], [255, 0, 0]]
], dtype=np.uint8)
fig = px.imshow(img_rgb)
fig.show()
I have tried to add transparency to the plot with the following code:
import plotly.express as px
import numpy as np
img_rgb = np.array([[[255, 0, 0, .5], [0, 255, 0, .5], [0, 0, 255, .5]],
[[0, 255, 0, .5], [0, 0, 255, .5], [255, 0, 0, .5]]
])
fig = px.imshow(img_rgb)
fig.show()
As suggested by the docs, passing a (M, N, 4), array would include transparency, but this resulted in an empty figure:

Using go.Image directly worked:
fig = go.Figure()
fig.add_traces(go.Image(z=img_rgb, colormodel='rgba'))

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 empty figure with the reported px.imshow example using a (M, N, 4) array, then compare it with the working go.Image example using colormodel='rgba'. Trace how px.imshow handles four-channel image input; done means px.imshow renders the image with transparency as documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100