Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] Aggregate hover data for internal nodes in hierarchical plots #4592

Open
evangelia96 opened this issue Apr 30, 2024 · 0 comments

Comments

@evangelia96
Copy link

Hierarchical plots constructed with px.treemap, px.icicle, and px.sunburst, aggregate data at internal nodes as follows:

  • values: sum of children,
  • color: values-weighted sum of children if df[color] is numeric, else "discrete aggregation",
  • hover_data: only supports "discrete aggregation",
    where for "discrete aggregation", the value of an internal node is mapped to that of its children if all its children have the same value, otherwise the aggregated value is set to "(?)".

Below is an example of a treemap with 2 quantities in hover data, one of which is numeric and could be aggregated at internal nodes, but instead all non-leaf nodes get a "(?)":

df = px.data.gapminder().query("year == 2007")
df["quantity_to_aggregate"] = np.random.random(df.shape[0])

fig = px.treemap(
    df,
    path=[px.Constant("world"), "continent", "country"],
    values="pop",
    color="lifeExp",
    hover_data=["iso_alpha", "quantity_to_aggregate"],
    color_continuous_scale="RdBu",
    color_continuous_midpoint=np.average(df["lifeExp"], weights=df["pop"]),
)
fig.update_layout(margin=dict(t=50, l=25, r=25, b=25))
fig.show()

Capture

Is it possible to aggregate numeric hover_data in hierarchical plots, perhaps as a sum initially, but potentially also giving the option to apply a different function?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants