如何更新 plotly express treemap 以同时具有标签和图中的值?
How to update plotly express treemap to have both label as well as the value inside the plot?
目前,plotly express treemap 仅显示树图中的标签。如何在标签旁边包含价值?
这就是我不喜欢 express 的原因,它有太多限制,要进行这些类型的更改,您必须以任何一种方式访问跟踪。在我看来,使用 plain plotly 更好,代码更透明。
也就是说,您可以访问跟踪的 textinfo
属性来执行此操作。来自 reference:
Determines which trace information appear on the graph.
Any combination of "label"
, "text"
, "value"
, "current path"
, "percent root"
, "percent entry"
, "percent parent"
joined with a "+"
OR "none"
.
以网站为例:
df = px.data.tips()
fig = px.treemap(df, path=['day', 'time', 'sex'], values='total_bill')
# this is what I don't like, accessing traces like this
fig.data[0].textinfo = 'label+text+value+current path'
fig.layout.hovermode = False
fig.show()
另请查看格式化选项的 texttemplate
属性。
目前,plotly express treemap 仅显示树图中的标签。如何在标签旁边包含价值?
这就是我不喜欢 express 的原因,它有太多限制,要进行这些类型的更改,您必须以任何一种方式访问跟踪。在我看来,使用 plain plotly 更好,代码更透明。
也就是说,您可以访问跟踪的 textinfo
属性来执行此操作。来自 reference:
Determines which trace information appear on the graph.
Any combination of
"label"
,"text"
,"value"
,"current path"
,"percent root"
,"percent entry"
,"percent parent"
joined with a"+"
OR"none"
.
以网站为例:
df = px.data.tips()
fig = px.treemap(df, path=['day', 'time', 'sex'], values='total_bill')
# this is what I don't like, accessing traces like this
fig.data[0].textinfo = 'label+text+value+current path'
fig.layout.hovermode = False
fig.show()
另请查看格式化选项的 texttemplate
属性。