【问题标题】:Plotly px.imshow show values in tilesPlotly px.imshow 在图块中显示值
【发布时间】:2021-12-23 09:45:26
【问题描述】:

我使用以下代码创建了一个热图:

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

当我将鼠标悬停在上面时,我可以看到“图块”的值。我希望在每个“图块”的热图中显示该值,这可能吗?

【问题讨论】:

    标签: python plotly


    【解决方案1】:

    这个想法是使用注释来显示各自的值,因为这不能直接在图形中完成。

    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)
    
    for i,r in enumerate(img_rgb):
        for k,c in enumerate(r):
            fig.add_annotation(x=k,y=i,
                               text='rgb:{}:{}:{}'.format(c[0],c[1],c[2]),
                               showarrow=False,
                              )
    fig.show()
    

    【讨论】:

      猜你喜欢
      • 2019-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-20
      相关资源
      最近更新 更多