Skip to content

Can not use transparency in px.imshow #2856

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
raphaeltimbo opened this issue Oct 23, 2020 · 0 comments
Open

Can not use transparency in px.imshow #2856

raphaeltimbo opened this issue Oct 23, 2020 · 0 comments
Labels
bug something broken P3 backlog

Comments

@raphaeltimbo
Copy link

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

@emmanuelle emmanuelle assigned emmanuelle and unassigned emmanuelle Oct 29, 2020
@emmanuelle emmanuelle self-assigned this Nov 5, 2020
@gvwilson gvwilson added P3 backlog bug something broken labels Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken P3 backlog
Projects
None yet
Development

No branches or pull requests

3 participants