Plotly px.imshow 在图块中显示值
Plotly px.imshow show values in tiles
我使用以下代码创建热图:
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()
当我将鼠标悬停在上面时,我可以看到“tile”的值。我希望在每个“图块”的热图中显示该值,这可能吗?
想法是使用注释来显示各个值,因为这不能直接在图形绘制中完成。
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()
我使用以下代码创建热图:
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()
当我将鼠标悬停在上面时,我可以看到“tile”的值。我希望在每个“图块”的热图中显示该值,这可能吗?
想法是使用注释来显示各个值,因为这不能直接在图形绘制中完成。
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()