In the sheet below, the columns ‘teto’ and ‘resto’ are being used to define the size of the squares and its colors, respectively. I filtered one path(eletricidade) as an example :
The code :
def grafico_arvore(dataframe):
import plotly.express as px
import numpy as np
import pandas as pd
df = dataframe
fig = px.treemap(df, path=['renda_despesa','categoria1', 'categoria2','categoria3'], values='teto',
color='resto', hover_data=['categoria3'],
color_continuous_scale='RdBu',
color_continuous_midpoint=np.average(df['resto'], weights=df['teto']))
fig.show()
The resulting chart :
The problem : The value ‘resto’ of the square ‘eletricidade’, highlighted in the chart image, is being showed as
263.2857(…), but it should be 348, since in the sheet (image) those 2 rows are the only ones matching the path of the ‘eletricidade’ square, and both sum is 348.
I think its a problem inside the function(grafico_arvore) … Something may be setted to do something else with the ‘resto’ column that isnt sum.