[英]Change hover text of a plotly express treemap
I want to show in a treemap just the label and value of each item, not parent or ID.我想在树形图中仅显示 label 和每个项目的值,而不是父项或 ID。 I have defined it with plotly express.
我已经用 plotly express 定义了它。 No matter how much I have tinkered with it, I haven't been able to restrict hover text to the fields I need.
无论我如何修改它,我都无法将 hover 文本限制为我需要的字段。 Check the code and capture
检查代码并捕获
import plotly.express as px
fig = px.treemap(dfconcepto, path=['type','name'],
values = 'count',
width=900, height=900,
hover_data = ['count'],
)
fig.show()
I also have tried to create it with non-express treemap.
我也尝试使用非表达树形图创建它。 Hovertext is what I want, but then a treemap with two levels is rendered asymmetric.
Hovertext 是我想要的,但是具有两个级别的树形图呈现为不对称的。
What I want is something like the hovertext of non-express treemap, but balanced and symmetric as in express treemap我想要的是类似于非表达树图的悬停文本,但与表达树图一样平衡和对称
What can I do?我能做些什么?
Thanks in advance!提前致谢!
It seems to me you should overwrite your hover template在我看来你应该覆盖你的 hover 模板
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.