plotly / plotly/plotly.py

add sort feature for icicle chart

Open
#4,555 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

feature P3
Dominant language
Python
Stars
18.8k
Forks
2.8k
Avg merge
16h 26m
Merged PRs (30d)
21

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the pandas and NumPy MWE using plotly.express.icicle and update_traces(sort=False). Start by tracing how the icicle chart handles sorting and hierarchy order; the work is done when an option preserves the input order for function calls and their children without weight or name sorting, with coverage for the shown example.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, pandas, python
Domain
data-visualization
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.