plotly.py icon indicating copy to clipboard operation
plotly.py copied to clipboard

Sort feature for icicle chart

Open ericsunplus opened this issue 11 months ago • 0 comments

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?

ericsunplus avatar Mar 21 '24 15:03 ericsunplus