|
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.0 |
10 | 10 | kernel_info:
|
11 | 11 | name: python2
|
12 | 12 | kernelspec:
|
@@ -143,6 +143,34 @@ 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. |
| 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 | + |
146 | 174 | ### Define Node Position
|
147 | 175 |
|
148 | 176 | 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