Plotly imshow中文翻译:imshow中的文本注释顺序

huangapple go评论67阅读模式
英文:

Order of Plotly Text Annotation in imshow

问题

以下是您要翻译的代码部分:

我无法理解文本注释的顺序因为它们在图像数组中的顺序我有一个形状为10x28x28的numpy数组每个子数组的值都是从0.1到0.9

from dash import Dash, dcc, html, Input, Output,callback
import plotly.express as px
import numpy as np

X = np.zeros((10,28,28))
y = np.zeros(10,)

for i in range(10):
   X[i,::,::] = i/10
   y[i] = i

fig = px.imshow(X[:, :, :], binary_string=False, zmin=0, zmax=1,
            facet_col=0, aspect = 'auto', facet_col_wrap=5,
            facet_row_spacing = 0, color_continuous_scale='rdylgn')

for n,i in enumerate(fig.layout.annotations):
   i['text']=str(n)

fig.show()

希望这对您有所帮助。如果您有任何其他问题,请随时提出。

英文:

I am not able to understand the order of text annotation as they appear in an array of images. I have a numpy array of 10x28x28 with each subarray having values 0.1,0.2 all the way to 0.9

from dash import Dash, dcc, html, Input, Output,callback
import plotly.express as px
import numpy as np

X = np.zeros((10,28,28))
y = np.zeros(10,)

for i in range(10):

   X[i,::,::] = i/10
   y[i] = i


fig = px.imshow(X[:, :, :], binary_string=False, zmin=0, zmax=1,
            facet_col=0, aspect = 'auto', facet_col_wrap=5,
            facet_row_spacing = 0, color_continuous_scale='rdylgn')

for n,i in enumerate(fig.layout.annotations):
   i['text']=str(n)

fig.show()

With the chosen color scheme, the 0th image should appear red and the 9th as green. All well so far. However , when I update the annotations with the array index , their order is completely haywire. The top-left image is the 0th subarray , hence it should have a text annotation of 0. Similarly , the bottom-right is the last subarray and it should have an annotation 9.
Please help me understand the order in which the text annotation can be controlled.

Plotly imshow中文翻译:imshow中的文本注释顺序

答案1

得分: 1

在这种情况下,这种现象发生是因为注释和图形的顺序不同。最简单的方法是使用默认创建的字幕来进行注释。

fig = px.imshow(X[:, :, :], binary_string=False, zmin=0, zmax=1,
            facet_col=0, aspect='auto', facet_col_wrap=5,
            facet_row_spacing=0, color_continuous_scale='rdylgn')

for n, i in enumerate(fig.layout.annotations):
   i['text'] = i.text.split('=')[1]

fig.show()
英文:

In this case, this phenomenon occurs because the order of annotations and graphs are different. It is easiest to use the subtitles, which are created by default, for the annotations.

fig = px.imshow(X[:, :, :], binary_string=False, zmin=0, zmax=1,
            facet_col=0, aspect = 'auto', facet_col_wrap=5,
            facet_row_spacing = 0, color_continuous_scale='rdylgn')

for n,i in enumerate(fig.layout.annotations):
   i['text']=i.text.split('=')[1]

fig.show()

Plotly imshow中文翻译:imshow中的文本注释顺序

huangapple
  • 本文由 发表于 2023年8月5日 15:00:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/76840486.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定