|
1 | 1 | """Demonstrate/test the Sankey class by producing a long chain of connections. |
2 | 2 | """ |
3 | | -import numpy as np |
4 | | -import matplotlib.pyplot as plt |
5 | 3 |
|
6 | | -from matplotlib.sankey import Sankey |
7 | 4 | from itertools import cycle |
8 | 5 |
|
| 6 | +import matplotlib.pyplot as plt |
| 7 | +from matplotlib.sankey import Sankey |
| 8 | + |
9 | 9 | links_per_side = 6 |
| 10 | + |
| 11 | + |
10 | 12 | def side(sankey, n=1): |
11 | | - """Generate a side chain. |
12 | | - """ |
| 13 | + """Generate a side chain.""" |
13 | 14 | prior = len(sankey.diagrams) |
14 | 15 | colors = cycle(['orange', 'b', 'g', 'r', 'c', 'm', 'y']) |
15 | 16 | for i in range(0, 2*n, 2): |
16 | 17 | sankey.add(flows=[1, -1], orientations=[-1, -1], |
17 | | - patchlabel=str(prior+i), facecolor=colors.next(), |
| 18 | + patchlabel=str(prior+i), facecolor=next(colors), |
18 | 19 | prior=prior+i-1, connect=(1, 0), alpha=0.5) |
19 | 20 | sankey.add(flows=[1, -1], orientations=[1, 1], |
20 | | - patchlabel=str(prior+i+1), facecolor=colors.next(), |
| 21 | + patchlabel=str(prior+i+1), facecolor=next(colors), |
21 | 22 | prior=prior+i, connect=(1, 0), alpha=0.5) |
| 23 | + |
| 24 | + |
22 | 25 | def corner(sankey): |
23 | | - """Generate a corner link. |
24 | | - """ |
| 26 | + """Generate a corner link.""" |
25 | 27 | prior = len(sankey.diagrams) |
26 | 28 | sankey.add(flows=[1, -1], orientations=[0, 1], |
27 | 29 | patchlabel=str(prior), facecolor='k', |
28 | 30 | prior=prior-1, connect=(1, 0), alpha=0.5) |
| 31 | + |
| 32 | + |
29 | 33 | fig = plt.figure() |
30 | 34 | ax = fig.add_subplot(1, 1, 1, xticks=[], yticks=[], |
31 | 35 | title="Why would you want to do this?\n(But you could.)") |
|
0 commit comments