I am trying to render text labels on a Heatmap. I have verified that I am running the latest version of Plotly (5.5.0), and am using the example code in the “Text on Heatmap Points” section on the Heatmaps webpage (Heatmaps). My code looks like the following:
from dash import Dash, dcc, html
import plotly.graph_objects as go
figHeatmap = go.Figure(
data=go.Heatmap(
z=[[1,20,30], [20,1,60], [30,60,1]],
text=[['1','2','3'],['4','5','6'],['7','8','9']],
texttemplate="%{text}",
textfont={"size":20}
)
)
figHeatmap.show()
# app = Dash()
# app.layout = html.Div([
# dcc.Graph(figure=figHeatmap)
# ])
#
# if __name__=='__main__':
# app.run_server()
My code is part of a Dash app, and when I run the application what I see is this:
whereas what I expect to see, according to the Heatmap webpage is this:
However, when I run the example interactively, and use fig.show()
, it does indeed work as expected. Therefore, I believe that my issue is with Dash and not with Plotly. Would that be a fair assessment? In any case, can anyone help me get the labels to show on the Heatmap when used in a Dash app? The labels do show on hover, but I’m looking for text labels without hovering.
Thanks!