|
8 | 8 |
|
9 | 9 |
|
10 | 10 | t = np.arange(0.0, 2, 0.01) |
11 | | -s = np.sin(2*np.pi*t) |
| 11 | +s1 = np.sin(2*np.pi*t) |
| 12 | +s2 = 1.2*np.sin(4*np.pi*t) |
12 | 13 |
|
13 | 14 | fig = plt.figure() |
14 | 15 | ax = fig.add_subplot(111) |
15 | | -ax.set_title('using fill_between_masked') |
16 | | -ax.plot(t, s, '-') |
| 16 | +ax.set_title('using fill_between_where') |
| 17 | +ax.plot(t, s1, t, s2) |
17 | 18 | ax.axhline(0, color='black', lw=2) |
18 | 19 |
|
19 | | -collection = collections.PolyCollection.fill_between_masked(t, s, s>=0, yboundary=0, color='green', alpha=0.5) |
| 20 | +collection = collections.PolyCollection.fill_between_where( |
| 21 | + t, s1, s2, s1>=s2, color='green', alpha=0.5) |
20 | 22 | ax.add_collection(collection) |
21 | 23 |
|
22 | | -collection = collections.PolyCollection.fill_between_masked(t, s, s<=0, yboundary=0, color='red', alpha=0.5) |
| 24 | +collection = collections.PolyCollection.fill_between_where( |
| 25 | + t, s1, s2, s1<=s2, color='red', alpha=0.5) |
23 | 26 | ax.add_collection(collection) |
24 | 27 |
|
25 | 28 |
|
26 | 29 | fig = plt.figure() |
27 | 30 | ax = fig.add_subplot(111) |
28 | 31 | ax.set_title('using span_masked') |
29 | | -ax.plot(t, s, '-') |
| 32 | +ax.plot(t, s1, '-') |
30 | 33 | ax.axhline(0, color='black', lw=2) |
31 | 34 |
|
32 | | -collection = collections.BrokenBarHCollection.span_masked(t, s>0, ymin=0, ymax=1, facecolor='green', alpha=0.5) |
| 35 | +collection = collections.BrokenBarHCollection.span_masked( |
| 36 | + t, s1>0, ymin=0, ymax=1, facecolor='green', alpha=0.5) |
33 | 37 | ax.add_collection(collection) |
34 | 38 |
|
35 | | -collection = collections.BrokenBarHCollection.span_masked(t, s<0, ymin=-1, ymax=0, facecolor='red', alpha=0.5) |
| 39 | +collection = collections.BrokenBarHCollection.span_masked( |
| 40 | + t, s1<0, ymin=-1, ymax=0, facecolor='red', alpha=0.5) |
36 | 41 | ax.add_collection(collection) |
37 | 42 |
|
38 | 43 |
|
|
0 commit comments