[英]How to show text on a heatmap with Plotly?
我試圖在 Plotly 熱圖中將z
項顯示為文本。 我正在使用最新版本 (5.5.0) 並遵循 Plotly 熱圖網頁 ( https://plotly.com/python/heatmaps/ ) 上顯示的確切示例,請參閱底部附近的“熱圖點文本”部分。
我的代碼是他們的示例代碼,即:
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}
)
)
當我運行我的應用程序時,我沒有收到任何錯誤,當我在熱圖上 hover 時,標簽確實顯示,但文本沒有按應有的方式顯示在熱圖上。 由於我使用的是他們的確切示例,因此我不明白可能出了什么問題。 有什么想法嗎?
[編輯]:這似乎是 Dash 的問題。 當我以交互方式運行示例時,我確實得到了文本標簽。 但是我的應用程序是 Dash 應用程序的一部分,這就是我看不到渲染標簽的地方。
auto_text
參數中的注釋的記錄示例,我對此進行了探索。
import plotly.express as px
import plotly.graph_objects as go
import inflect
p = inflect.engine()
df = px.data.medals_wide(indexed=True)
fig = px.imshow(df, text_auto=True)
fig2 = go.Figure(fig.data, fig.layout)
fig2 = fig2.update_traces(text=df.applymap(p.number_to_words).values, texttemplate="%{text}", hovertemplate=None)
fig.show()
fig2.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.