I am trying to use custom data in the texttemplate of a Heatmap in Plotly, but it does not seem to work. I am using Python 3.10.12 and Plotly 5.15.0. Below there is a MWE:
import plotly.express as px
import numpy
df = px.data.medals_wide(indexed=True)
fig = px.imshow(df)
customdata = numpy.zeros(df.shape)
fig.data[0].customdata = customdata
fig.data[0].hovertemplate = 'Custom data: %{customdata}' # This works fine.
fig.data[0].texttemplate = '%{customdata}' # This fails.
fig.write_html('deleteme.html',include_plotlyjs='cdn')



customdatais "not user-visible but is included in events emitted by the figure" (ie. hover, click, select, etc.), so you can use it inhovertemplate(hover event) or in Dash callbacks, but not directly as text. As mentioned by @r-beginners, what can be used fortexttemplateis what you set fortext.