简体   繁体   中英

How to update plotly express treemap to have both label as well as the value inside the plot?

Currently, plotly express treemap shows only label inside treemap. How to include the value alongside the label?

That's why I don't like express, there are too many limitations and to make these kinds of changes you have to access the trace either way. From my point of view it is better and more code-transparent to use plain plotly instead.

That being said, you can access the textinfo attribute of the trace to do this. From the 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" .

Taking an example from the site:

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()

例子

Also take a look at the texttemplate attribute for formatting options.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM