Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change titles (facet_col )in imshow (plotly)

Tags:

python

plotly

I want to plot several images with imshow from plotly and give each image a title.

My code is

fig = px.imshow(numpy.array(img1,img2), color_continuous_scale='gray', facet_col=0, labels={'facet_col' : 'status'})
fig.update_xaxes(showticklabels=False).update_yaxes(showticklabels=False)
fig.show()

and the result looks like

enter image description here

However, I would like to replace status=0 with original and status=1 with clean. Is there an easy way to achieve this result?

Thanks for any help.

like image 696
DerJFK Avatar asked Oct 12 '25 04:10

DerJFK


1 Answers

I solved my problem by

fig = px.imshow(
  numpy.array(img1,img2), 
  color_continuous_scale='gray', 
  facet_col=0
)

fig.update_xaxes(showticklabels=False).update_yaxes(showticklabels=False)

for i, label in enumerate(['orignal', 'clean']):
    fig.layout.annotations[i]['text'] = label

fig.show()

It would be nice, if there would be a shorter way e.g. passing the list of labels directly to the imshow command. However, I did not find any possibility to do that.

like image 162
DerJFK Avatar answered Oct 14 '25 16:10

DerJFK