How to set a plotly tree chart to calculate the sum instead of the average of the children values, with python?

The official description about this chart code says : " If a color argument is passed, the color of a node is computed as the average of the color values of its children, weighted by their values. " But i need the color to be the sum of the childrens, not the average. Is it possible ?

import plotly.express as px
import numpy as np
df = px.data.gapminder().query("year == 2007")
fig = px.sunburst(df, path=['continent', 'country'], values='pop',
                  color='lifeExp', hover_data=['iso_alpha'],
                  color_continuous_scale='RdBu',
                  color_continuous_midpoint=np.average(df['lifeExp'], weights=df['pop']))
fig.show()
1 Like

Hi, @vic131!
Did you solve this question? Iā€™d like to do the same thing, show the sum of children instead of the average.