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
description: How to make Sankey Diagrams in Python with Plotly.
17
28
display_as: basic
@@ -27,198 +38,86 @@ jupyter:
27
38
title: Sankey Diagram | Plotly
28
39
---
29
40
30
-
#### New to Plotly?
31
-
Plotly's Python library is free and open source! [Get started](https://plot.ly/python/getting-started/) by downloading the client and [reading the primer](https://plot.ly/python/getting-started/).
32
-
<br>You can set up Plotly to work in [online](https://plot.ly/python/getting-started/#initialization-for-online-plotting) or [offline](https://plot.ly/python/getting-started/#initialization-for-offline-plotting) mode, or in [jupyter notebooks](https://plot.ly/python/getting-started/#start-plotting-online).
33
-
<br>We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started!
34
-
41
+
A [Sankey diagram](https://en.wikipedia.org/wiki/Sankey_diagram) is a flow diagram, in which the width of arrows is proportional to the flow quantity.
35
42
36
-
#### Version Check
37
-
Plotly's python package is updated frequently. Run `pip install plotly --upgrade` to use the latest version.
source= [0,1, 0, 2, 3, 3],# indices correspond to labels, eg A1, A2, A2, B1, ...
59
+
target= [2,3, 3, 4, 4, 5],
60
+
value= [8,4, 2, 8, 4, 2]
65
61
))
66
62
67
-
layout =dict(
68
-
title="Basic Sankey Diagram",
69
-
font=dict(
70
-
size=10
71
-
)
72
-
)
73
-
74
-
fig =dict(data=[data], layout=layout)
75
-
py.iplot(fig, validate=False)
76
-
```
77
-
78
-
### Create Sankey Canvas
79
-
80
-
```python inputHidden=false outputHidden=false
81
-
import plotly.plotly as py
82
63
83
-
data =dict(
84
-
type='sankey',
85
-
domain=dict(
86
-
x= [0,1],
87
-
y= [0,1]
88
-
),
89
-
orientation="h",
90
-
valueformat=".0f",
91
-
valuesuffix="TWh"
92
-
)
93
-
94
-
layout =dict(
95
-
title="Energy forecast for 2050<br>Source: Department of Energy & Climate Change, Tom Counsell via <a href='https://bost.ocks.org/mike/sankey/'>Mike Bostock</a>",
title="Energy forecast for 2050<br>Source: Department of Energy & Climate Change, Tom Counsell via <a href='https://bost.ocks.org/mike/sankey/'>Mike Bostock</a>",
title="Energy forecast for 2050<br>Source: Department of Energy & Climate Change, Tom Counsell via <a href='https://bost.ocks.org/mike/sankey/'>Mike Bostock</a>",
183
-
font=dict(
184
-
size=10
185
-
)
186
-
)
187
-
188
-
fig =dict(data=[data_trace], layout=layout)
189
-
py.iplot(fig, validate=False)
97
+
fig = go.Figure(data=[data_trace])
98
+
fig.update(layout_title_text="Energy forecast for 2050<br>Source: Department of Energy & Climate Change, Tom Counsell via <a href='https://bost.ocks.org/mike/sankey/'>Mike Bostock</a>",
title="Energy forecast for 2050<br>Source: Department of Energy & Climate Change, Tom Counsell via <a href='https://bost.ocks.org/mike/sankey/'>Mike Bostock</a>",
232
-
font=dict(
233
-
size=10,
234
-
color='white'
235
-
),
131
+
font=dict(size=10, color='white'),
236
132
plot_bgcolor='black',
237
133
paper_bgcolor='black'
238
134
)
239
-
240
-
fig =dict(data=[data_trace], layout=layout)
241
-
py.iplot(fig, validate=False)
135
+
fig = go.Figure(data=[data_trace], layout=layout)
136
+
fig.show()
242
137
```
243
138
244
139
### Reference
245
140
246
141
See [https://plot.ly/python/reference/#sankey](https://plot.ly/python/reference/#sankey) for more information and options!
0 commit comments