plotly / plotly/plotly.py

Can not use transparency in px.imshow

Open
#2,856 0 comments 1 reaction 0 assignees View on GitHub

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:
image

Using go.Image directly worked:

fig = go.Figure()
fig.add_traces(go.Image(z=img_rgb, colormodel='rgba'))

image

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.