简体   繁体   中英

Is it possible to change rectangle ordenation in Plotly treemap?

I want to make a treemap following a predefined ordering, but I don't know how to manipulate the hierarchy defined by plotly treemap .

Here is the treemap I've created:

已创建树状图

Here I want the O to be above the U box and the UR to be a unique column, without dividing its space with NA .

Here is my code:

import plotly.graph_objects as go

fig = go.Figure(go.Treemap(
    labels = ["DR","1,2","D 1","D 2","O","U",
              "3,4,5","P","B","Pe",
              "6,7,8","F","C","Pl",
              "9","UR",
              "10","NA"],
    parents = ["", "DR", "1,2","1,2","1,2","1,2","DR","3,4,5","3,4,5","3,4,5",
               "DR","6,7,8","6,7,8","6,7,8",
               "DR","9",
                "DR","10"],
    marker_colors = ["lightgrey", 
                      "lightblue", "cornflowerblue", "cornflowerblue","goldenrod","green",
                      "lightblue","lightgray","chocolate","cadetblue",
                      "lightblue","grey",'chocolate',"saddlebrown",
                      "salmon","salmon",
                      "burlywood","burlywood",
                      ],
    branchvalues="total"
))

fig.update_layout(margin = dict(t=10, l=60, r=25, b=30))
fig.show()

Much appreciated!

I've tried creating values for each rectangle, but it didn't help and didn't work as expected.

You need the argument tiling . I think this is what you're asking for.

import plotly.graph_objects as go

fig = go.Figure(go.Treemap(
    labels = ["DR","1,2","D 1","D 2","O","U",
              "3,4,5","P","B","Pe",
              "6,7,8","F","C","Pl",
              "9","UR",
              "10","NA"],
    parents = ["", "DR", "1,2","1,2","1,2","1,2","DR","3,4,5","3,4,5","3,4,5",
               "DR","6,7,8","6,7,8","6,7,8",
               "DR","9",
                "DR","10"],
    marker_colors = ["lightgrey", 
                      "lightblue", "cornflowerblue", "cornflowerblue","goldenrod","green",
                      "lightblue","lightgray","chocolate","cadetblue",
                      "lightblue","grey",'chocolate',"saddlebrown",
                      "salmon","salmon",
                      "burlywood","burlywood",
                      ],
    branchvalues="total",
    tiling = dict(packing='slice-dice')
))

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM