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: doc/python/sankey-diagram.md
+35-3
Original file line number
Diff line number
Diff line change
@@ -5,8 +5,8 @@ jupyter:
5
5
text_representation:
6
6
extension: .md
7
7
format_name: markdown
8
-
format_version: '1.1'
9
-
jupytext_version: 1.2.1
8
+
format_version: '1.2'
9
+
jupytext_version: 1.3.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.7.3
25
+
version: 3.6.8
26
26
plotly:
27
27
description: How to make Sankey Diagrams in Python with Plotly.
28
28
display_as: basic
@@ -143,6 +143,38 @@ fig.update_layout(
143
143
fig.show()
144
144
```
145
145
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. For more information about hovertemplate and customdata, please see the [tutorial on hover text](/python/hover-text-and-formatting/).
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='Node %{customdata} has total value %{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
+
customdata= ["q","r","s","t","u","v"],
169
+
hovertemplate='Link from node %{source.customdata}<br />'+
170
+
'to node%{target.customdata}<br />has value %{value}'+
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:<fontcolor='blue'> 1)</font> perpendicular <fontcolor='blue'>2)</font> freeform <fontcolor='blue'>3)</font> fixed
0 commit comments