更改 plotly express 树状图的悬停文本

Change hover text of a plotly express treemap

我只想在树图中显示每个项目的标签和值,而不是父项或 ID。我已经用 plotly express 定义了它。无论我如何修改它,我都无法将悬停文本限制在我需要的字段中。检查代码并捕获

import plotly.express as px

fig = px.treemap(dfconcepto, path=['type','name'], 
                 values = 'count',
                 width=900, height=900,
                 hover_data = ['count'],
)

fig.show()

image
image
1117×957 44.9 KB 我也尝试用非快速树图创建它。悬停文本是我想要的,但是具有两个级别的树状图呈现为不对称。

我想要的是类似于非表达树图的悬停文本,但像表达树图一样平衡和对称

我能做什么?

提前致谢!

在我看来你应该覆盖你的悬停模板

import pandas as pd
import plotly.express as px
url = "https://gist.githubusercontent.com/jlchulilla/3b4e40f68ba73b5dbcb661a1d861f308/raw/e564973db30a4612aba60c5b26dd108edc98f048/test2sof.csv"

df = pd.read_csv(url).drop("Unnamed: 0", axis=1)

fig = px.treemap(df, path=['type','name'], 
                 values = 'coincidencia',
                 width=900, height=900,
)

# Now your hovertemplate looks like
# fig.data[0].hovertemplate 
# 'labels=%{label}<br>coincidencia=%{value}<br>parent=%{parent}<br>id=%{id}<extra></extra>'

# But it seems to me you want something like
fig.data[0].hovertemplate = '%{label}<br>%{value}'
fig.show()