Sankey diagram

A Sankey Diagram is a visualisation technique that allows to display flows. Several entities (nodes) are represented by rectangles or text. Their links are represented with arrows or arcs that have a width proportional to the importance of the flow.

Plotly logoSankey diagram with Plotly

Plotly is an awesome Python library for interactive data visualization. It is most probably the best tool to create a Sankey Diagram. Its Sankey() function handles most of the business logic for you, allowing to get a figure in a couple of lines of code.

The blogpost linked below should quickly get you started with some minimal starting example. It also describes the most common of type of customization you probably want to apply to your Sankey diagram to make it appealing, and ends up with the code for a real life Sankey diagram shown below.

Sankey diagrams with pySankey

The pySankey python library by anazalea is another option when it comes to build sankey diagrams. It is based on matplotlib and aims a building static outputs only. The blogpost showcased below should help you to get started quickly, describing the various accepted dataset and the customization offered by the library.


👋 This document is a work by Yan Holtz. You can contribute on github, send me a feedback on twitter or subscribe to the newsletter to know when new examples are published! 🔥