Skip to content

Commit 3ed402d

Browse files
committed
minimal example with customdata for sankey nodes
1 parent f622085 commit 3ed402d

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

doc/python/sankey-diagram.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ jupyter:
55
text_representation:
66
extension: .md
77
format_name: markdown
8-
format_version: '1.1'
9-
jupytext_version: 1.2.1
8+
format_version: '1.2'
9+
jupytext_version: 1.3.0
1010
kernel_info:
1111
name: python2
1212
kernelspec:
@@ -143,6 +143,34 @@ fig.update_layout(
143143
fig.show()
144144
```
145145

146+
### Hovertemplate and customdata of Sankey diagrams
147+
148+
Links and nodes have their own hovertemplate, in which link- or node-specific attributes can be displayed. To add more data to links and nodes, it is possible to use the `customdata` attribute of `link` and `nodes`, as in the following example.
149+
150+
```python
151+
import plotly.graph_objects as go
152+
153+
fig = go.Figure(data=[go.Sankey(
154+
node = dict(
155+
pad = 15,
156+
thickness = 20,
157+
line = dict(color = "black", width = 0.5),
158+
label = ["A1", "A2", "B1", "B2", "C1", "C2"],
159+
customdata = ["Long name A1", "Long name A2", "Long name B1", "Long name B2",
160+
"Long name C1", "Long name C2"],
161+
hovertemplate='%{customdata} <br> %{value} <extra></extra>',
162+
color = "blue"
163+
),
164+
link = dict(
165+
source = [0, 1, 0, 2, 3, 3], # indices correspond to labels, eg A1, A2, A2, B1, ...
166+
target = [2, 3, 3, 4, 4, 5],
167+
value = [8, 4, 2, 8, 4, 2]
168+
))])
169+
170+
fig.update_layout(title_text="Basic Sankey Diagram", font_size=10)
171+
fig.show()
172+
```
173+
146174
### Define Node Position
147175

148176
The following example sets [node.x](https://plotly.com/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://plotly.com/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

0 commit comments

Comments
 (0)