2

I am trying to get a treemap with plotly that shows the sum of two quantities on hovering (length and height) for each group

I can do that with one of them, but not with the other. What I have now is:

import pandas as pd
import plotly.express as px

data = {
    "group": ["A", "A", "B", "B", "B", "C"],
    "subgroup": ["A1", "A2", "B1", "B2", "B3", "C1"],
    "lenght": [10, 11, 20, 21, 22, 30],
    "height": [110, 111, 220, 221, 222, 330],
}

df = pd.DataFrame(data)
fig = px.treemap(
    df,
    path=[px.Constant("all"), "group", "subgroup"],
    values="lenght",
    hover_data=["lenght", "height"],
)
fig.update_traces(textinfo="value")
fig.show()

And the result of hovering is this one: current state enter image description here

I would like the question mark to be the sum of all children heights, How can this be achieved?

Subbu VidyaSekar
  • 2,503
  • 3
  • 21
  • 39
Alexis
  • 21
  • 2
  • Check out this answer: https://stackoverflow.com/questions/60575662/how-to-update-plotly-express-treemap-to-have-both-label-as-well-as-the-value-ins – Yevgeniy Gendelman Aug 18 '22 at 21:49

0 Answers0