英文:
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.
答案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()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论