Sugikey
Sugikey in a nutshell
Sugikey allows you to draw Sankey diagrams and related flow diagrams in Python. Sankey diagrams are flow diagrams composed of arrows of width proportional to the flow of e.g. energy or mass. We use the Sugiyama method to derive layered graph layouts, hence the portmanteau Sugi(yama)(San)key.
Some key facts:
- Consumes pandas dataframes or networkx directed graphs as inputs.
- Uses NetworkX for processing of the underlying graph structure.
- Produces visual output with Matplotlib.
- Limitation: the created diagrams are not interactive, i.e. the arrows cannot be moved. Interactive Sankey diagrams can be created with a variety of other tools, including d3-Sankey.
Getting started
The simplest way to use the package are the high-level functions sankey_from_dig and sankey_from_df, which take as input a networkx directed graph and a pandas dataframe, respectively.
from sugikey import examples, sankey
# Sankey diagram from a networkx directed graph
dig = examples.balanced_tree_with_cross_edge()
sankey.sankey_from_dig(dig)
# Sankey diagram from a pandas dataframe
flow_df = pd.read_csv(csv_path)
sankey.sankey_from_df(flow_df)