@@ -380,11 +380,13 @@ def imshow(
380
380
381
381
# For 2D+RGB data, use Image trace
382
382
elif img .ndim == 3 and img .shape [- 1 ] in [3 , 4 ] or (img .ndim == 2 and binary_string ):
383
+ rescale_image = True # to check whether image has been modified
383
384
if zmin is not None and zmax is not None :
384
385
zmin , zmax = _vectorize_zvalue (zmin ), _vectorize_zvalue (zmax )
385
386
if binary_string :
386
- if zmin is None and zmax is None :
387
+ if zmin is None and zmax is None : # no rescaling, faster
387
388
img_rescaled = img
389
+ rescale_image = False
388
390
elif img .ndim == 2 :
389
391
img_rescaled = rescale_intensity (
390
392
img , in_range = (zmin [0 ], zmax [0 ]), out_range = np .uint8
@@ -429,19 +431,23 @@ def imshow(
429
431
fig = go .Figure (data = trace , layout = layout )
430
432
fig .update_layout (layout_patch )
431
433
# Hover name, z or color
432
- if binary_string and not (img_rescaled .max () == img .max ()):
434
+ if binary_string and rescale_image and not (img_rescaled .max () == img .max ()):
435
+ # we rescaled the image, hence z is not displayed in hover since it does
436
+ # not correspond to img values
433
437
hovertemplate = "%s: %%{x}<br>%s: %%{y}<extra></extra>" % (
434
438
labels ["x" ] or "x" ,
435
439
labels ["y" ] or "y" ,
436
440
)
437
441
else :
438
442
if trace ["type" ] == "heatmap" :
439
- hover_name = "z "
443
+ hover_name = "%{z} "
440
444
elif img .ndim == 2 :
441
- hover_name = "color[0]"
445
+ hover_name = "%{z[0]}"
446
+ elif img .ndim == 3 and img .shape [- 1 ] == 3 :
447
+ hover_name = "[%{z[0]}, %{z[1]}, %{z[2]}]"
442
448
else :
443
- hover_name = "color "
444
- hovertemplate = "%s: %%{x}<br>%s: %%{y}<br>%s: %%{%s} <extra></extra>" % (
449
+ hover_name = "%{z} "
450
+ hovertemplate = "%s: %%{x}<br>%s: %%{y}<br>%s: %s <extra></extra>" % (
445
451
labels ["x" ] or "x" ,
446
452
labels ["y" ] or "y" ,
447
453
labels ["color" ] or "color" ,
0 commit comments