Can not use transparency in px.imshow
未关闭
还没有人认领这个 Issue。
bug
P3
- 主要语言
- Python
- 星标
- 18.8k
- 派生
- 2.8k
- 平均合并
- 16 小时 26 分钟
- 30 天内合并 PR
- 21
描述
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'))

贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
使用 (M, N, 4) 数组通过报告的 px.imshow 示例重现空图,然后将其与使用 colormodel='rgba' 的正常工作的 go.Image 示例进行比较。跟踪 px.imshow 如何处理四通道图像输入;当 px.imshow 按文档所述以透明度渲染图像时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- numpy, python
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 38/100