Extra data in hover over a heatmap

I don’t understand why this works and my previous try didn’t, but I discovered this by serendipity and tinkering with the code at Hover text and formatting in Python

import plotly.graph_objects as go
from plotly.subplots import make_subplots
import numpy as np
np.random.seed(0)
z1 = np.random.random((3, 3))
uppercase = [['ONE', 'TWENTY', 'THIRTY'],
                          ['TWENTY', 'ONE', 'SIXTY'],
                          ['THIRTY', 'SIXTY', 'ONE']]
data = np.dstack(( uppercase,))
fig = make_subplots()
fig.add_trace(go.Heatmap(
    z=[[1, 20, 30],
                  [20, 1, 60],
                  [30, 60, 1]],
                   text=[['one', 'twenty', 'thirty'],
                          ['twenty', 'one', 'sixty'],
                          ['thirty', 'sixty', 'one']],
         texttemplate="--%{text}--",
    customdata=data,
    hovertemplate='<b>%{customdata[0]}</b>',
    coloraxis="coloraxis1", name=''),
    1, 1)

fig.update_layout(title_text='Hover for Extra Data !!')
fig.show()
1 Like