Treemap Hovertext


I am trying to create a treemap. The dataframe df_all_trees has some more columns which I would like to display as information on hovering. How do I add this data into a variable that can be then used in hovertemplate?

    hovertemplate='<b>%{label} </b> <br> Last Close: %{value}',
    name='' ), 1, 1)

Hi @saboo.anuj17 you can add your additional data in the customdata attribute of go.Treemap and then access the customdata in the hovertemplate as described in

Maybe you could also use px.treemap here, in which case you can pass the additional columns to the hover_data argument of px.treemap, and then they will be added automatically to the hovertemplate. See for example the example in

import as px
df =
fig = px.violin(df, y="tip", x="smoker", color="sex", box=True, points="all", hover_data=df.columns)

Hi @Emmanuelle thanks for your help. I was not able to get around the array stacking to get to my desired solution, however the px.treemap case worked well. Thank you very much.

In addition to this, would you be able to help me to disable hover text for hierarchies? I am trying to build a multi-level treemap and I do not want the hovertext to display for the hierarchies because the respective values would not be present. Eg. For stock market, I would have data for stock but not for it’s sector(eg. IT).

Hi @saboo.anuj17 if you want to remove information from the default hover, you’ll need to modify the hovertemplate of the figure. You can do print(fig) to see the hovertemplate which is used in your current figure and modify it with fig.update_traces(hovertemplate=...).

Hi @Emmanuelle I realize this is an old conversation, but it has helped me along. I have one small follow-up question: is there a way to have the print(fig) output be more verbose? In my session, it is abridging with a “…” string the section I am most interested in. :-/

Hi @kehliah,

According to: Hover Text and Formatting | Python | Plotly

the following print command should work: