Santiago Veintimilla
Santiago Veintimilla

Reputation: 61

Setting group order on pySankey sankey chart

I'm trying to use a sankey chart to show some user segmentation change using PySankey but the class order is the opposite to what I want. Is there a way for me to specify the order in which each class is posted? Here is the code I'm using (a dummy version):

test_df = pd.DataFrame({
    'curr_seg':np.repeat(['A','B','C','D'],4),
    'new_seg':['A','B','C','D']*4,
    'num_users':np.random.randint(low=10, high=20, size=16)
})

sankey(
    left=test_df["curr_seg"], right=test_df["new_seg"], 
    leftWeight= test_df["num_users"], rightWeight=test_df["num_users"], 
    aspect=20, fontsize=20
)

Which produces this chart:

Sankey Chart

I want to have the A class first and the D class latest on both left and right axis. Does anybody know how can I set it up? Thank you very much.

Upvotes: 1

Views: 986

Answers (2)

Pierre.Sassoulas
Pierre.Sassoulas

Reputation: 4282

The bug that IIIIR is talking about is fixed in pySankeyBeta, install it with pip install pySankeyBeta instead.

Upvotes: 0

IIIIR
IIIIR

Reputation: 41

There is a bug in the first line of check_data_matches_labels function, you need to change to the following: if len(labels) > 0: Then you can use leftLabels and rightLabels to control order.

Upvotes: 3

Related Questions