|
1 | 1 | #!/usr/bin/env python |
2 | 2 | import matplotlib.mlab as mlab |
3 | | -from pylab import figure, show |
| 3 | +from matplotlib.pyplot import figure, show |
4 | 4 | import numpy as np |
5 | 5 |
|
6 | 6 | x = np.arange(0.0, 2, 0.01) |
|
27 | 27 | # fill_between(x[where], y1[where],y2[where] |
28 | 28 | # because of edge effects over multiple contiguous regions. |
29 | 29 | fig = figure() |
30 | | -ax = fig.add_subplot(111) |
| 30 | +ax = fig.add_subplot(211) |
31 | 31 | ax.plot(x, y1, x, y2, color='black') |
32 | | -ax.fill_between(x, y1, y2, where=y2>y1, facecolor='green') |
| 32 | +ax.fill_between(x, y1, y2, where=y2>=y1, facecolor='green') |
33 | 33 | ax.fill_between(x, y1, y2, where=y2<=y1, facecolor='red') |
34 | 34 | ax.set_title('fill between where') |
35 | 35 |
|
| 36 | +# Test support for masked arrays. |
| 37 | +y2 = np.ma.masked_greater(y2, 1.0) |
| 38 | +ax1 = fig.add_subplot(212, sharex=ax) |
| 39 | +ax1.plot(x, y1, x, y2, color='black') |
| 40 | +ax1.fill_between(x, y1, y2, where=y2>=y1, facecolor='green') |
| 41 | +ax1.fill_between(x, y1, y2, where=y2<=y1, facecolor='red') |
| 42 | +ax1.set_title('Now regions with y2>1 are masked') |
| 43 | + |
| 44 | +# This example illustrates a problem; because of the data |
| 45 | +# gridding, there are undesired unfilled triangles at the crossover |
| 46 | +# points. A brute-force solution would be to interpolate all |
| 47 | +# arrays to a very fine grid before plotting. |
| 48 | + |
36 | 49 | show() |
37 | 50 |
|
0 commit comments