FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
matplotlib.github.com/2.2.0/gallery/api/sankey_basics.py at main · matplotlib/matplotlib.github.com · GitHub
matplotlib
/
matplotlib.github.com
Public
Notifications
You must be signed in to change notification settings
Fork
62
Star
29
Code
Issues
1
Pull requests
2
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
matplotlib.github.com
/
2.2.0
/
gallery
/
api
/
sankey_basics.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
102 lines (87 loc) · 3.74 KB
Breadcrumbs
matplotlib.github.com
/
2.2.0
/
gallery
/
api
/
sankey_basics.py
Copy path
File metadata and controls
102 lines (87 loc) · 3.74 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
"""
================
The Sankey class
================
Demonstrate the Sankey class by producing three basic diagrams.
"""
import
numpy
as
np
import
matplotlib
.
pyplot
as
plt
from
matplotlib
.
sankey
import
Sankey
###############################################################################
# Example 1 -- Mostly defaults
#
# This demonstrates how to create a simple diagram by implicitly calling the
# Sankey.add() method and by appending finish() to the call to the class.
Sankey
(
flows
=
[
0.25
,
0.15
,
0.60
,
-
0.20
,
-
0.15
,
-
0.05
,
-
0.50
,
-
0.10
],
labels
=
[
''
,
''
,
''
,
'First'
,
'Second'
,
'Third'
,
'Fourth'
,
'Fifth'
],
orientations
=
[
-
1
,
1
,
0
,
1
,
1
,
1
,
0
,
-
1
]).
finish
()
plt
.
title
(
"The default settings produce a diagram like this."
)
###############################################################################
# Notice:
#
# 1. Axes weren't provided when Sankey() was instantiated, so they were
# created automatically.
# 2. The scale argument wasn't necessary since the data was already
# normalized.
# 3. By default, the lengths of the paths are justified.
###############################################################################
# Example 2
#
# This demonstrates:
#
# 1. Setting one path longer than the others
# 2. Placing a label in the middle of the diagram
# 3. Using the scale argument to normalize the flows
# 4. Implicitly passing keyword arguments to PathPatch()
# 5. Changing the angle of the arrow heads
# 6. Changing the offset between the tips of the paths and their labels
# 7. Formatting the numbers in the path labels and the associated unit
# 8. Changing the appearance of the patch and the labels after the figure is
# created
fig
=
plt
.
figure
()
ax
=
fig
.
add_subplot
(
1
,
1
,
1
,
xticks
=
[],
yticks
=
[],
title
=
"Flow Diagram of a Widget"
)
sankey
=
Sankey
(
ax
=
ax
,
scale
=
0.01
,
offset
=
0.2
,
head_angle
=
180
,
format
=
'%.0f'
,
unit
=
'%'
)
sankey
.
add
(
flows
=
[
25
,
0
,
60
,
-
10
,
-
20
,
-
5
,
-
15
,
-
10
,
-
40
],
labels
=
[
''
,
''
,
''
,
'First'
,
'Second'
,
'Third'
,
'Fourth'
,
'Fifth'
,
'Hurray!'
],
orientations
=
[
-
1
,
1
,
0
,
1
,
1
,
1
,
-
1
,
-
1
,
0
],
pathlengths
=
[
0.25
,
0.25
,
0.25
,
0.25
,
0.25
,
0.6
,
0.25
,
0.25
,
0.25
],
patchlabel
=
"Widget
\n
A"
)
# Arguments to matplotlib.patches.PathPatch()
diagrams
=
sankey
.
finish
()
diagrams
[
0
].
texts
[
-
1
].
set_color
(
'r'
)
diagrams
[
0
].
text
.
set_fontweight
(
'bold'
)
###############################################################################
# Notice:
#
# 1. Since the sum of the flows is nonzero, the width of the trunk isn't
# uniform. If verbose.level is helpful (in matplotlibrc), a message is
# given in the terminal window.
# 2. The second flow doesn't appear because its value is zero. Again, if
# verbose.level is helpful, a message is given in the terminal window.
###############################################################################
# Example 3
#
# This demonstrates:
#
# 1. Connecting two systems
# 2. Turning off the labels of the quantities
# 3. Adding a legend
fig
=
plt
.
figure
()
ax
=
fig
.
add_subplot
(
1
,
1
,
1
,
xticks
=
[],
yticks
=
[],
title
=
"Two Systems"
)
flows
=
[
0.25
,
0.15
,
0.60
,
-
0.10
,
-
0.05
,
-
0.25
,
-
0.15
,
-
0.10
,
-
0.35
]
sankey
=
Sankey
(
ax
=
ax
,
unit
=
None
)
sankey
.
add
(
flows
=
flows
,
label
=
'one'
,
orientations
=
[
-
1
,
1
,
0
,
1
,
1
,
1
,
-
1
,
-
1
,
0
])
sankey
.
add
(
flows
=
[
-
0.25
,
0.15
,
0.1
],
label
=
'two'
,
orientations
=
[
-
1
,
-
1
,
-
1
],
prior
=
0
,
connect
=
(
0
,
0
))
diagrams
=
sankey
.
finish
()
diagrams
[
-
1
].
patch
.
set_hatch
(
'/'
)
plt
.
legend
(
loc
=
'best'
)
###############################################################################
# Notice that only one connection is specified, but the systems form a
# circuit since: (1) the lengths of the paths are justified and (2) the
# orientation and ordering of the flows is mirrored.
plt
.
show
()
Back
|
FazBrowse Home
|
New Git URL