Skip to content

Commit 5f6327b

Browse files
authored
Merge pull request #189 from plotly/sankey_node_position
sankey nodes position
2 parents f326de1 + 8471dcb commit 5f6327b

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

python/sankey-diagram.md

+27-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.1'
9-
jupytext_version: 1.1.1
9+
jupytext_version: 1.2.1
1010
kernel_info:
1111
name: python2
1212
kernelspec:
@@ -22,7 +22,7 @@ jupyter:
2222
name: python
2323
nbconvert_exporter: python
2424
pygments_lexer: ipython3
25-
version: 3.6.7
25+
version: 3.7.3
2626
plotly:
2727
description: How to make Sankey Diagrams in Python with Plotly.
2828
display_as: basic
@@ -39,6 +39,7 @@ A [Sankey diagram](https://en.wikipedia.org/wiki/Sankey_diagram) is a flow diagr
3939

4040

4141
### 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.
4243

4344
```python
4445
import plotly.graph_objects as go
@@ -64,6 +65,7 @@ fig.show()
6465
### More complex Sankey diagram
6566

6667
```python inputHidden=false outputHidden=false
68+
import plotly.graph_objects as go
6769
import urllib, json
6870

6971
url = 'https://raw.githubusercontent.com/plotly/plotly.js/master/test/image/mocks/sankey_energy.json'
@@ -96,6 +98,7 @@ fig.show()
9698
### Style Sankey Diagram
9799

98100
```python
101+
import plotly.graph_objects as go
99102
import urllib, json
100103

101104
url = 'https://raw.githubusercontent.com/plotly/plotly.js/master/test/image/mocks/sankey_energy.json'
@@ -129,6 +132,28 @@ fig.update_layout(
129132
fig.show()
130133
```
131134

135+
### Define Node Position
136+
137+
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:<font color='blue'> 1)</font> perpendicular <font color='blue'>2)</font> freeform <font color='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+
132157
### Reference
133158

134159
See [https://plot.ly/python/reference/#sankey](https://plot.ly/python/reference/#sankey) for more information and options!

0 commit comments

Comments
 (0)