|  | 
| 11 | 11 | from matplotlib.sankey import Sankey | 
| 12 | 12 | 
 | 
| 13 | 13 | 
 | 
|  | 14 | +############################################################################### | 
| 14 | 15 | # Example 1 -- Mostly defaults | 
|  | 16 | +# | 
| 15 | 17 | # This demonstrates how to create a simple diagram by implicitly calling the | 
| 16 | 18 | # Sankey.add() method and by appending finish() to the call to the class. | 
|  | 19 | + | 
| 17 | 20 | Sankey(flows=[0.25, 0.15, 0.60, -0.20, -0.15, -0.05, -0.50, -0.10], | 
| 18 | 21 |        labels=['', '', '', 'First', 'Second', 'Third', 'Fourth', 'Fifth'], | 
| 19 | 22 |        orientations=[-1, 1, 0, 1, 1, 1, 0, -1]).finish() | 
| 20 | 23 | plt.title("The default settings produce a diagram like this.") | 
|  | 24 | + | 
|  | 25 | +############################################################################### | 
| 21 | 26 | # Notice: | 
| 22 |  | -#   1. Axes weren't provided when Sankey() was instantiated, so they were | 
| 23 |  | -#      created automatically. | 
| 24 |  | -#   2. The scale argument wasn't necessary since the data was already | 
| 25 |  | -#      normalized. | 
| 26 |  | -#   3. By default, the lengths of the paths are justified. | 
|  | 27 | +# | 
|  | 28 | +# 1. Axes weren't provided when Sankey() was instantiated, so they were | 
|  | 29 | +#    created automatically. | 
|  | 30 | +# 2. The scale argument wasn't necessary since the data was already | 
|  | 31 | +#    normalized. | 
|  | 32 | +# 3. By default, the lengths of the paths are justified. | 
| 27 | 33 | 
 | 
|  | 34 | + | 
|  | 35 | +############################################################################### | 
| 28 | 36 | # Example 2 | 
|  | 37 | +# | 
| 29 | 38 | # This demonstrates: | 
| 30 |  | -#   1. Setting one path longer than the others | 
| 31 |  | -#   2. Placing a label in the middle of the diagram | 
| 32 |  | -#   3. Using the scale argument to normalize the flows | 
| 33 |  | -#   4. Implicitly passing keyword arguments to PathPatch() | 
| 34 |  | -#   5. Changing the angle of the arrow heads | 
| 35 |  | -#   6. Changing the offset between the tips of the paths and their labels | 
| 36 |  | -#   7. Formatting the numbers in the path labels and the associated unit | 
| 37 |  | -#   8. Changing the appearance of the patch and the labels after the figure is | 
| 38 |  | -#      created | 
|  | 39 | +# | 
|  | 40 | +# 1. Setting one path longer than the others | 
|  | 41 | +# 2. Placing a label in the middle of the diagram | 
|  | 42 | +# 3. Using the scale argument to normalize the flows | 
|  | 43 | +# 4. Implicitly passing keyword arguments to PathPatch() | 
|  | 44 | +# 5. Changing the angle of the arrow heads | 
|  | 45 | +# 6. Changing the offset between the tips of the paths and their labels | 
|  | 46 | +# 7. Formatting the numbers in the path labels and the associated unit | 
|  | 47 | +# 8. Changing the appearance of the patch and the labels after the figure is | 
|  | 48 | +#    created | 
|  | 49 | + | 
| 39 | 50 | fig = plt.figure() | 
| 40 | 51 | ax = fig.add_subplot(1, 1, 1, xticks=[], yticks=[], | 
| 41 | 52 |                      title="Flow Diagram of a Widget") | 
|  | 
| 51 | 62 | diagrams = sankey.finish() | 
| 52 | 63 | diagrams[0].texts[-1].set_color('r') | 
| 53 | 64 | diagrams[0].text.set_fontweight('bold') | 
|  | 65 | + | 
|  | 66 | +############################################################################### | 
| 54 | 67 | # Notice: | 
| 55 |  | -#   1. Since the sum of the flows is nonzero, the width of the trunk isn't | 
| 56 |  | -#      uniform.  If verbose.level is helpful (in matplotlibrc), a message is | 
| 57 |  | -#      given in the terminal window. | 
| 58 |  | -#   2. The second flow doesn't appear because its value is zero.  Again, if | 
| 59 |  | -#      verbose.level is helpful, a message is given in the terminal window. | 
|  | 68 | +# | 
|  | 69 | +# 1. Since the sum of the flows is nonzero, the width of the trunk isn't | 
|  | 70 | +#    uniform.  If verbose.level is helpful (in matplotlibrc), a message is | 
|  | 71 | +#    given in the terminal window. | 
|  | 72 | +# 2. The second flow doesn't appear because its value is zero.  Again, if | 
|  | 73 | +#    verbose.level is helpful, a message is given in the terminal window. | 
|  | 74 | + | 
| 60 | 75 | 
 | 
|  | 76 | +############################################################################### | 
| 61 | 77 | # Example 3 | 
|  | 78 | +# | 
| 62 | 79 | # This demonstrates: | 
| 63 |  | -#   1. Connecting two systems | 
| 64 |  | -#   2. Turning off the labels of the quantities | 
| 65 |  | -#   3. Adding a legend | 
|  | 80 | +# | 
|  | 81 | +# 1. Connecting two systems | 
|  | 82 | +# 2. Turning off the labels of the quantities | 
|  | 83 | +# 3. Adding a legend | 
|  | 84 | + | 
| 66 | 85 | fig = plt.figure() | 
| 67 | 86 | ax = fig.add_subplot(1, 1, 1, xticks=[], yticks=[], title="Two Systems") | 
| 68 | 87 | flows = [0.25, 0.15, 0.60, -0.10, -0.05, -0.25, -0.15, -0.10, -0.35] | 
|  | 
| 74 | 93 | diagrams = sankey.finish() | 
| 75 | 94 | diagrams[-1].patch.set_hatch('/') | 
| 76 | 95 | plt.legend(loc='best') | 
|  | 96 | + | 
|  | 97 | +############################################################################### | 
| 77 | 98 | # Notice that only one connection is specified, but the systems form a | 
| 78 | 99 | # circuit since: (1) the lengths of the paths are justified and (2) the | 
| 79 | 100 | # orientation and ordering of the flows is mirrored. | 
|  | 
0 commit comments