4 interactive Sankey diagrams made in Python
Plotly has a new member of the Plotly.js chart family: The Sankey diagram. Allow us to introduce you:
Sankey diagrams were invented to chart energy flows (such as through a steam engine). As an example, you might start with 100% of a fuel’s energy on the left side of the diagram, then X% is lost to friction, Y% is lost to compressing the fuel, and Z% is used for propulsion — these losses are shown on the right side of the diagram. Connecting the left and the right sides are ribbons whose widths are proportional to the flow magnitude. This simplified example would show 3 ribbons for 3 energy flows, but practical Sankey diagrams can have dozens (or hundreds) of ribbons. Sankey diagrams are still used in science and engineering for charting energy flows.
Today, Sankey diagrams are commonly seen charting the flow of website traffic. Consider the case where 1,000 website visitors start on 3 landing pages, then trickle off to hundreds of sub-pages before they leave the site entirely. Analysts use these diagrams to understand which pages get the most traffic, how the traffic arrives, and where the visitors go afterwards.
Plotly Sankey diagrams come supercharged with a few extra features:
- Hover labels — Add labels to sources, sinks, and flows so that your audience knows what they’re seeing when inspecting a complicated Sankey diagram.
- You can track the flow of individual items through a Plotly Sankey diagram. For example, the screenshot below shows one of 400 drones highlighted through all stages of its lifecycle. This tracking feature could be useful in manufacturing: Imagine tracking thousands of battery cells through the stages of an electric vehicle manufacturing line. The Sankey diagram could start with the delivery of the cells at the factory and end when they are installed in a completed car.
Without further ado, here are 4 interactive Sankey diagrams made in Python. The Python code to make these is in this Jupyter notebook hosted on plot.ly.
Refugee Migration through Manus and Nauru
400 Military Drone Crashes
Changing Views of Scottish Voters
Energy Forecast for 2050
You can reproduce these charts yourself in Python using this Jupyter notebook.
Footnote on terminology: Plotly’s Sankey diagrams are technically “alluvial flow diagrams,” because they can only trace flow in one direction. A true Sankey diagram can cycle a flow back to its source (such as waste heat being recycled for combustion in an engine, or regenerative breaking in an electric car). “Alluvial flow diagram” doesn’t roll off the tongue, however, so we’re sticking with the commonly recognized (and still correct) “Sankey diagram.”