|
11 | 11 | from matplotlib.sankey import Sankey |
12 | 12 |
|
13 | 13 |
|
| 14 | +############################################################################### |
14 | 15 | # Example 1 -- Mostly defaults |
15 | 16 | # This demonstrates how to create a simple diagram by implicitly calling the |
16 | 17 | # Sankey.add() method and by appending finish() to the call to the class. |
17 | 18 | Sankey(flows=[0.25, 0.15, 0.60, -0.20, -0.15, -0.05, -0.50, -0.10], |
18 | 19 | labels=['', '', '', 'First', 'Second', 'Third', 'Fourth', 'Fifth'], |
19 | 20 | orientations=[-1, 1, 0, 1, 1, 1, 0, -1]).finish() |
20 | 21 | plt.title("The default settings produce a diagram like this.") |
| 22 | +############################################################################### |
21 | 23 | # Notice: |
22 | 24 | # 1. Axes weren't provided when Sankey() was instantiated, so they were |
23 | 25 | # created automatically. |
24 | 26 | # 2. The scale argument wasn't necessary since the data was already |
25 | 27 | # normalized. |
26 | 28 | # 3. By default, the lengths of the paths are justified. |
27 | 29 |
|
| 30 | +############################################################################### |
28 | 31 | # Example 2 |
29 | 32 | # This demonstrates: |
30 | 33 | # 1. Setting one path longer than the others |
|
51 | 54 | diagrams = sankey.finish() |
52 | 55 | diagrams[0].texts[-1].set_color('r') |
53 | 56 | diagrams[0].text.set_fontweight('bold') |
| 57 | +############################################################################### |
54 | 58 | # Notice: |
55 | 59 | # 1. Since the sum of the flows is nonzero, the width of the trunk isn't |
56 | 60 | # uniform. If verbose.level is helpful (in matplotlibrc), a message is |
57 | 61 | # given in the terminal window. |
58 | 62 | # 2. The second flow doesn't appear because its value is zero. Again, if |
59 | 63 | # verbose.level is helpful, a message is given in the terminal window. |
60 | 64 |
|
| 65 | +############################################################################### |
61 | 66 | # Example 3 |
62 | 67 | # This demonstrates: |
63 | 68 | # 1. Connecting two systems |
|
74 | 79 | diagrams = sankey.finish() |
75 | 80 | diagrams[-1].patch.set_hatch('/') |
76 | 81 | plt.legend(loc='best') |
| 82 | +############################################################################### |
77 | 83 | # Notice that only one connection is specified, but the systems form a |
78 | 84 | # circuit since: (1) the lengths of the paths are justified and (2) the |
79 | 85 | # orientation and ordering of the flows is mirrored. |
|
0 commit comments