@@ -168,7 +168,9 @@ def imshow(
168168 args = locals ()
169169 apply_default_cascade (args )
170170 img_is_xarray = False
171- z_name = ""
171+ x_label = "x"
172+ y_label = "y"
173+ z_label = ""
172174 if xarray_imported :
173175 if isinstance (img , xarray .DataArray ):
174176 y_label , x_label = img .dims [0 ], img .dims [1 ]
@@ -181,15 +183,15 @@ def imshow(
181183 img_is_xarray = True
182184 if aspect is None :
183185 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>" )
185187
186188 if labels is not None :
187189 if "x" in labels :
188- y_label = labels ["x" ]
190+ x_label = labels ["x" ]
189191 if "y" in labels :
190192 y_label = labels ["y" ]
191193 if "color" in labels :
192- z_name = labels ["color" ]
194+ z_label = labels ["color" ]
193195
194196 if not img_is_xarray :
195197 if aspect is None :
@@ -222,7 +224,7 @@ def imshow(
222224 cmid = color_continuous_midpoint ,
223225 cmin = range_color [0 ],
224226 cmax = range_color [1 ],
225- colorbar = dict (title = z_name ),
227+ colorbar = dict (title = z_label ),
226228 )
227229
228230 # For 2D+RGB data, use Image trace
@@ -248,18 +250,19 @@ def imshow(
248250 layout_patch ["margin" ] = {"t" : 60 }
249251 fig = go .Figure (data = trace , layout = layout )
250252 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 )
251263 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 )
264267 fig .update_layout (template = args ["template" ], overwrite = True )
265268 return fig
0 commit comments