Python Plotly Go Treemap not showing all levels

18 Views Asked by At

I'm trying to build a treemap with Plotly Go, but for some reason it won't show all the items. There's only 2 levels, and the first item of the first level will show all of its children, but none of the others do

If it makes a difference, I'm using google colab, but I've also tried it with Jupyter Notebook and I got the same thing.

This is the data:

    id  parent  value   Abbv    Color
0   Agriculture     China   653.97  AGR     #fea652
1   Agriculture     India   741.92  AGR     #fea652
2   Agriculture     Russia  104.13  AGR     #fea652
3   Agriculture     United States   382.01  AGR     #fea652
4   Building    China   492.89  BLDG    #ffc583
5   Building    India   162.49  BLDG    #ffc583
6   Building    Russia  212.21  BLDG    #ffc583
7   Building    United States   517.21  BLDG    #ffc583
8   Bunker Fuels    China   54.42   BF  #88814b
9   Bunker Fuels    India   8.92    BF  #88814b
10  Bunker Fuels    Russia  36.02   BF  #88814b
11  Bunker Fuels    United States   97.07   BF  #88814b
12  Electricity/Heat    China   5713.98     E/H     #c33116
13  Electricity/Heat    India   1121.98     E/H     #c33116
14  Electricity/Heat    Russia  822.41  E/H     #c33116
15  Electricity/Heat    United States   1771.12     E/H     #c33116
16  Energy  China   10818.71    E   #a41623
17  Energy  India   2224.18     E   #a41623
18  Energy  Russia  2054.92     E   #a41623
19  Energy  United States   4744.20     E   #a41623
20  Fugitive Emissions  China   628.07  FUG     #ffba6e
21  Fugitive Emissions  India   88.99   FUG     #ffba6e
22  Fugitive Emissions  Russia  492.00  FUG     #ffba6e
23  Fugitive Emissions  United States   419.50  FUG     #ffba6e
24  Industrial Processes    China   1260.69     IND     #fb862e
25  Industrial Processes    India   149.37  IND     #fb862e
26  Industrial Processes    Russia  53.74   IND     #fb862e
27  Industrial Processes    United States   243.52  IND     #fb862e
28  Manufacturing/Construction  China   2899.05     M/C     #e24b09
29  Manufacturing/Construction  India   509.45  M/C     #e24b09
30  Manufacturing/Construction  Russia  274.64  M/C     #e24b09
31  Manufacturing/Construction  United States   441.12  M/C     #e24b09
32  Other Fuel Combustion   China   163.79  Other   #b8a06b
33  Other Fuel Combustion   India   64.83   Other   #b8a06b
34  Other Fuel Combustion   Russia  13.70   Other   #b8a06b
35  Other Fuel Combustion   United States   36.94   Other   #b8a06b
36  Transportation  China   920.94  TRNS    #f9660a
37  Transportation  India   276.44  TRNS    #f9660a
38  Transportation  Russia  239.97  TRNS    #f9660a
39  Transportation  United States   1558.32     TRNS    #f9660a
40  Waste   China   209.50  W   #e0bc87
41  Waste   India   85.35   W   #e0bc87
42  Waste   Russia  118.68  W   #e0bc87
43  Waste   United States   135.45  W   #e0bc87
44  China       23816.01    China   #000000
45  India       5433.92     India   #000000
46  Russia      4422.42     Russia  #000000
47  United States       10346.46    United States   #000000

This is the code:

    import plotly.graph_objects as go
    import pandas as pd
    import numpy as np
    
    fig = go.Figure(go.Treemap(
        labels = df5['Abbv'],
        values = df5['value'],
        parents = df5['parent'],
        branchvalues='total',
        marker_colors  = df5['Color'],
        maxdepth=3
    ))
    
    fig.update_layout(margin = dict(t=50, l=25, r=25, b=25),
                  height=1000,width=1000)
    
    fig.show()

I've also tried maxdepth=-1 but I get the same result

Plotly Go Treemap without all items

0

There are 0 best solutions below