You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: python/sankey-diagram.md
+27-2
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ jupyter:
6
6
extension: .md
7
7
format_name: markdown
8
8
format_version: '1.1'
9
-
jupytext_version: 1.1.1
9
+
jupytext_version: 1.2.1
10
10
kernel_info:
11
11
name: python2
12
12
kernelspec:
@@ -22,7 +22,7 @@ jupyter:
22
22
name: python
23
23
nbconvert_exporter: python
24
24
pygments_lexer: ipython3
25
-
version: 3.6.7
25
+
version: 3.7.3
26
26
plotly:
27
27
description: How to make Sankey Diagrams in Python with Plotly.
28
28
display_as: basic
@@ -39,6 +39,7 @@ A [Sankey diagram](https://en.wikipedia.org/wiki/Sankey_diagram) is a flow diagr
39
39
40
40
41
41
### Basic Sankey Diagram
42
+
Sankey diagrams visualize the contributions to a flow by defining [source](https://plot.ly/python/reference/#sankey-link-source) to represent the source node, [target](https://plot.ly/python/reference/#sankey-link-target) for the target node, [value](https://plot.ly/python/reference/#sankey-link-value) to set the flow volum, and [label](https://plot.ly/python/reference/#sankey-node-label) that shows the node name.
The following example sets [node.x](https://plot.ly/python/reference/#sankey-node-x) and `node.y` to place nodes in the specified locations, except in the `snap arrangement` (default behaviour when `node.x` and `node.y` are not defined) to avoid overlapping of the nodes, therefore, an automatic snapping of elements will be set to define the padding between nodes via [nodepad](https://plot.ly/python/reference/#sankey-node-pad). The other possible arrangements are:<fontcolor='blue'> 1)</font> perpendicular <fontcolor='blue'>2)</font> freeform <fontcolor='blue'>3)</font> fixed
138
+
139
+
```python
140
+
import plotly.graph_objects as go
141
+
142
+
fig = go.Figure(go.Sankey(
143
+
arrangement="snap",
144
+
node= {
145
+
"label": ["A", "B", "C", "D", "E", "F"],
146
+
"x": [0.2, 0.1, 0.5, 0.7, 0.3, 0.5],
147
+
"y": [0.7, 0.5, 0.2, 0.4, 0.2, 0.3],
148
+
'pad':10}, # 10 Pixels
149
+
link= {
150
+
"source": [0, 0, 1, 2, 5, 4, 3, 5],
151
+
"target": [5, 3, 4, 3, 0, 2, 2, 3],
152
+
"value": [1, 2, 1, 1, 1, 1, 1, 2]}))
153
+
154
+
fig.show()
155
+
```
156
+
132
157
### Reference
133
158
134
159
See [https://plot.ly/python/reference/#sankey](https://plot.ly/python/reference/#sankey) for more information and options!
0 commit comments