@@ -168,7 +168,9 @@ def imshow(
168
168
args = locals ()
169
169
apply_default_cascade (args )
170
170
img_is_xarray = False
171
- z_name = ""
171
+ x_label = "x"
172
+ y_label = "y"
173
+ z_label = ""
172
174
if xarray_imported :
173
175
if isinstance (img , xarray .DataArray ):
174
176
y_label , x_label = img .dims [0 ], img .dims [1 ]
@@ -181,15 +183,15 @@ def imshow(
181
183
img_is_xarray = True
182
184
if aspect is None :
183
185
aspect = "auto"
184
- z_name = xarray .plot .utils .label_from_attrs (img ).replace ("\n " , "<br>" )
186
+ z_label = xarray .plot .utils .label_from_attrs (img ).replace ("\n " , "<br>" )
185
187
186
188
if labels is not None :
187
189
if "x" in labels :
188
- y_label = labels ["x" ]
190
+ x_label = labels ["x" ]
189
191
if "y" in labels :
190
192
y_label = labels ["y" ]
191
193
if "color" in labels :
192
- z_name = labels ["color" ]
194
+ z_label = labels ["color" ]
193
195
194
196
if not img_is_xarray :
195
197
if aspect is None :
@@ -222,7 +224,7 @@ def imshow(
222
224
cmid = color_continuous_midpoint ,
223
225
cmin = range_color [0 ],
224
226
cmax = range_color [1 ],
225
- colorbar = dict (title = z_name ),
227
+ colorbar = dict (title = z_label ),
226
228
)
227
229
228
230
# For 2D+RGB data, use Image trace
@@ -248,18 +250,19 @@ def imshow(
248
250
layout_patch ["margin" ] = {"t" : 60 }
249
251
fig = go .Figure (data = trace , layout = layout )
250
252
fig .update_layout (layout_patch )
253
+ if img .ndim <= 2 :
254
+ hovertemplate = (
255
+ x_label
256
+ + ": %{x} <br>"
257
+ + y_label
258
+ + ": %{y} <br>"
259
+ + z_label
260
+ + " : %{z}<extra></extra>"
261
+ )
262
+ fig .update_traces (hovertemplate = hovertemplate )
251
263
if img_is_xarray :
252
- if img .ndim <= 2 :
253
- hovertemplate = (
254
- x_label
255
- + ": %{x} <br>"
256
- + y_label
257
- + ": %{y} <br>"
258
- + z_name
259
- + " : %{z}<extra></extra>"
260
- )
261
- fig .update_traces (x = x , y = y , hovertemplate = hovertemplate )
262
- fig .update_xaxes (title_text = x_label )
263
- fig .update_yaxes (title_text = y_label )
264
+ fig .update_traces (x = x , y = y )
265
+ fig .update_xaxes (title_text = x_label )
266
+ fig .update_yaxes (title_text = y_label )
264
267
fig .update_layout (template = args ["template" ], overwrite = True )
265
268
return fig
0 commit comments