File tree Expand file tree Collapse file tree 2 files changed +21
-9
lines changed
packages/python/plotly/plotly Expand file tree Collapse file tree 2 files changed +21
-9
lines changed Original file line number Diff line number Diff line change @@ -422,21 +422,25 @@ def imshow(
422
422
fig = go .Figure (data = trace , layout = layout )
423
423
fig .update_layout (layout_patch )
424
424
# Hover name, z or color
425
- if trace ["type" ] == "heatmap" :
426
- hover_name = "z"
427
- elif img .ndim == 2 :
428
- hover_name = "color[0]"
425
+ if binary_string and not (img_rescaled .max () == img .max ()):
426
+ hovertemplate = "%s: %%{x}<br>%s: %%{y}<extra></extra>" % (
427
+ labels ["x" ] or "x" ,
428
+ labels ["y" ] or "y" ,
429
+ )
429
430
else :
430
- hover_name = "color"
431
- fig .update_traces (
432
- hovertemplate = "%s: %%{x}<br>%s: %%{y}<br>%s: %%{%s}<extra></extra>"
433
- % (
431
+ if trace ["type" ] == "heatmap" :
432
+ hover_name = "z"
433
+ elif img .ndim == 2 :
434
+ hover_name = "color[0]"
435
+ else :
436
+ hover_name = "color"
437
+ hovertemplate = "%s: %%{x}<br>%s: %%{y}<br>%s: %%{%s}<extra></extra>" % (
434
438
labels ["x" ] or "x" ,
435
439
labels ["y" ] or "y" ,
436
440
labels ["color" ] or "color" ,
437
441
hover_name ,
438
442
)
439
- )
443
+ fig . update_traces ( hovertemplate = hovertemplate )
440
444
if labels ["x" ]:
441
445
fig .update_xaxes (title_text = labels ["x" ])
442
446
if labels ["y" ]:
Original file line number Diff line number Diff line change @@ -285,3 +285,11 @@ def test_imshow_hovertemplate(binary_string):
285
285
fig .data [0 ].hovertemplate
286
286
== "x: %{x}<br>y: %{y}<br>color: %{color}<extra></extra>"
287
287
)
288
+ fig = px .imshow (img_gray , binary_string = binary_string )
289
+ if binary_string :
290
+ assert fig .data [0 ].hovertemplate == "x: %{x}<br>y: %{y}<extra></extra>"
291
+ else :
292
+ assert (
293
+ fig .data [0 ].hovertemplate
294
+ == "x: %{x}<br>y: %{y}<br>color: %{z}<extra></extra>"
295
+ )
You can’t perform that action at this time.
0 commit comments