Skip to content

Commit 378f9aa

Browse files
committed
Add sankey node alignment
1 parent 8c9fa2d commit 378f9aa

File tree

1 file changed

+52
-4
lines changed

1 file changed

+52
-4
lines changed

doc/python/sankey-diagram.md

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.3'
9-
jupytext_version: 1.14.1
9+
jupytext_version: 1.14.6
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.8.8
25+
version: 3.10.11
2626
plotly:
2727
description: How to make Sankey Diagrams in Python with Plotly.
2828
display_as: basic
@@ -49,7 +49,7 @@ fig = go.Figure(data=[go.Sankey(
4949
pad = 15,
5050
thickness = 20,
5151
line = dict(color = "black", width = 0.5),
52-
label = ["A1", "A2", "B1", "B2", "C1", "C2"],
52+
# label = ["A1", "A2", "A1", "B2", "C1", "C2"],
5353
color = "blue"
5454
),
5555
link = dict(
@@ -229,7 +229,8 @@ fig = go.Figure(go.Sankey(
229229
label=['A', 'B', 'C', 'D', 'E', 'F'],
230230
x=[0.2, 0.1, 0.5, 0.7, 0.3, 0.5],
231231
y=[0.7, 0.5, 0.2, 0.4, 0.2, 0.3],
232-
pad=10
232+
pad=10 ,
233+
align="right",
233234
),
234235
link=dict(
235236
arrowlen=15,
@@ -242,6 +243,53 @@ fig = go.Figure(go.Sankey(
242243
fig.show()
243244
```
244245

246+
### Node Alignment
247+
248+
*New in 5.18*
249+
250+
You can set the alignment of nodes using `node.align`. Here are two examples with the same `source` and `target`. The first example has nodes aligned "left" and the second has nodes aligned "right". `node.align` also supports "center" and "justify". "justify" is the default if `node.align` is not set, and is similar to aligning to the "left", except that nodes without outgoing links are moved to the right of the figure.
251+
252+
```python
253+
import plotly.graph_objects as go
254+
255+
fig = go.Figure(go.Sankey(
256+
arrangement='snap',
257+
node=dict(
258+
label=["0", "1", "2", "3", "4", "5"],
259+
align='left'
260+
261+
),
262+
link=dict(
263+
arrowlen=15,
264+
source=[0, 1, 4, 2, 1],
265+
target=[1, 4, 5, 4, 3],
266+
value=[4, 2, 3, 1, 2]
267+
)
268+
))
269+
270+
fig.show()
271+
```
272+
273+
```python
274+
import plotly.graph_objects as go
275+
276+
fig = go.Figure(go.Sankey(
277+
arrangement='snap',
278+
node=dict(
279+
label=["0", "1", "2", "3", "4", "5"],
280+
align="right",
281+
),
282+
link=dict(
283+
arrowlen=15,
284+
source=[0, 1, 4, 2, 1],
285+
target=[1, 4, 5, 4, 3],
286+
value=[4, 2, 3, 1, 2]
287+
)
288+
))
289+
290+
fig.show()
291+
```
292+
245293
### Reference
246294

247295
See [https://plotly.com/python/reference/sankey](https://plotly.com/python/reference/sankey/) for more information and options!

0 commit comments

Comments
 (0)