|
1 | 1 | """ |
2 | 2 | Illustrate some helper functions for shading regions where a logical |
3 | 3 | mask is True |
| 4 | +
|
| 5 | +See :meth:`matplotlib.collections.PolyCollection.fill_between_where` |
| 6 | +and :meth:`matplotlib.collections.BrokenBarHCollection.span_where` |
4 | 7 | """ |
5 | 8 | import numpy as np |
6 | 9 | import matplotlib.pyplot as plt |
|
18 | 21 | ax.axhline(0, color='black', lw=2) |
19 | 22 |
|
20 | 23 | collection = collections.PolyCollection.fill_between_where( |
21 | | - t, s1, s2, s1>=s2, color='green', alpha=0.5) |
| 24 | + t, s1, s2, where=s1>=s2, color='green', alpha=0.5) |
22 | 25 | ax.add_collection(collection) |
23 | 26 |
|
24 | 27 | collection = collections.PolyCollection.fill_between_where( |
25 | | - t, s1, s2, s1<=s2, color='red', alpha=0.5) |
| 28 | + t, s1, s2, where=s1<=s2, color='red', alpha=0.5) |
26 | 29 | ax.add_collection(collection) |
27 | 30 |
|
28 | 31 |
|
29 | 32 | fig = plt.figure() |
30 | 33 | ax = fig.add_subplot(111) |
31 | | -ax.set_title('using span_masked') |
| 34 | +ax.set_title('using span_where') |
32 | 35 | ax.plot(t, s1, '-') |
33 | 36 | ax.axhline(0, color='black', lw=2) |
34 | 37 |
|
35 | | -collection = collections.BrokenBarHCollection.span_masked( |
36 | | - t, s1>0, ymin=0, ymax=1, facecolor='green', alpha=0.5) |
| 38 | +collection = collections.BrokenBarHCollection.span_where( |
| 39 | + t, ymin=0, ymax=1, where=s1>0, facecolor='green', alpha=0.5) |
37 | 40 | ax.add_collection(collection) |
38 | 41 |
|
39 | | -collection = collections.BrokenBarHCollection.span_masked( |
40 | | - t, s1<0, ymin=-1, ymax=0, facecolor='red', alpha=0.5) |
| 42 | +collection = collections.BrokenBarHCollection.span_where( |
| 43 | + t, ymin=-1, ymax=0, where=s1<0, facecolor='red', alpha=0.5) |
41 | 44 | ax.add_collection(collection) |
42 | 45 |
|
43 | 46 |
|
|
0 commit comments