The Sankey diagram is a diagram that represents the flow rate between processes. The thickness of the arrow indicates the amount of flow. In particular, it is used to represent the displacement of energy, supplies, expenses, etc.
[Source: Free encyclopedia "Wikipedia"](https://ja.wikipedia.org/wiki/%E3%82%B5%E3%83%B3%E3%82%AD%E3%83%BC_ % E3% 83% 80% E3% 82% A4% E3% 82% A2% E3% 82% B0% E3% 83% A9% E3% 83% A0)
I don't understand the original matplotlib
at all, and plotly
is very beautiful but I don't understand at all. Try with the simplest demo: Exporting Images.ipynb!
sankey.py
from ipysankeywidget import SankeyWidget
from ipywidgets import Layout
pip install ipysankey widget
.jupyter lab
,$ jupyter labextension install jupyter-sankey-widget @jupyter-widgets/jupyterlab-manager
And register the extension.
sankey.py
links = [
{'source': 'start', 'target': 'A', 'value': 2},
{'source': 'A', 'target': 'B', 'value': 2},
{'source': 'C', 'target': 'A', 'value': 2},
{'source': 'A', 'target': 'C', 'value': 2},
]
Since this is the data part, replace it with the transfer dummy data.
sankey.py
links = [
{'source': 'Hokkaido_in', 'target': 'overseas_out', 'value': 1},
{'source': 'Hokkaido_in', 'target': 'J2_out', 'value': 1},
{'source': 'Hokkaido_in', 'target': 'University_out', 'value': 3},
{'source': 'Shonan_in', 'target': 'Hokkaido_out', 'value': 1},
{'source': 'J3_in', 'target': 'Hokkaido_out', 'value': 1},
]
sankey.py
layout = Layout(width="600", height="400")
sankey = SankeyWidget(links=links, layout=layout)
sankey.auto_save_png('./img/test.png')
The size of the output image is 600 pixels wide and 400 pixels high and is saved in PNG format.
Needless to say, I was able to express the flow of 5 players who joined and 2 players who transferred. (Look at it, but it seems that you can express the flow for the time being)
Recommended Posts