Skip to content

add sort feature for icicle chart #4555

Open
@ericsunplus

Description

@ericsunplus

I want to use icicle chart to show function call stacks, the MWE is as the following

import pandas as pd
import numpy as np
import plotly.express as px

data = np.array(
        [
            ["main", "A-Func", None, 1],
            ["main", "C-Func", "sub1", 1],
            ["main", "C-Func", "sub2", 1],
            ["main", "B-Func", None, 1],
            ["main", "D-func", "sub1", 1],
            ["main", "D-func", "sub2", 1],
            ["main", "D-func", "sub3", 1],
        ]
        )

df = pd.DataFrame(data, columns = ['Level0', 'Level1', 'Level2', 'Weight'])
fig = px.icicle(df, path=['Level0', 'Level1', 'Level2'], values='Weight')
fig.update_traces(root_color="lightblue")
fig.show()

This is yielding a graph sorted by both Weight and Name

enter image description here

If I added sort parameter

fig.update_traces(root_color="lightblue", sort=False)

The weight is not sorted, however the name are still sorted

enter image description here

What I want to achieve is the nature order of these function calls as I create the numpy object

main
  |
  +--- A-Func
  |
  +--- C-Func
  |     |
  |     +--- sub1
  |     |
  |     +--- sub2
  |
  +--- B-Func
  |
  +--- D-Func
        |
        +--- sub1
        |
        +--- sub2
        |
        +--- sub3

Is there some option I can use to achieve this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3backlogfeaturesomething new

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions