|
1 |
| -""" |
2 |
| -Copy of fill_between.py but using fill_betweenx() instead. |
3 |
| -""" |
4 | 1 | import matplotlib.mlab as mlab
|
5 | 2 | from matplotlib.pyplot import figure, show
|
6 | 3 | import numpy as np
|
7 | 4 |
|
8 | 5 |
|
9 |
| -x = np.arange(0.0, 2, 0.01) |
10 |
| -y1 = np.sin(2*np.pi*x) |
11 |
| -y2 = 1.2*np.sin(4*np.pi*x) |
| 6 | +y = np.arange(0.0, 2, 0.01) |
| 7 | +x1 = np.sin(2*np.pi*y) |
| 8 | +x2 = 1.2*np.sin(4*np.pi*y) |
12 | 9 |
|
13 | 10 | fig = figure()
|
14 | 11 | ax1 = fig.add_subplot(311)
|
15 | 12 | ax2 = fig.add_subplot(312, sharex=ax1)
|
16 | 13 | ax3 = fig.add_subplot(313, sharex=ax1)
|
17 | 14 |
|
18 |
| -ax1.fill_betweenx(x, 0, y1) |
19 |
| -ax1.set_ylabel('(y1, 0)') |
| 15 | +ax1.fill_betweenx(y, 0, x1) |
| 16 | +ax1.set_ylabel('(x1, 0)') |
20 | 17 |
|
21 |
| -ax2.fill_betweenx(x, y1, 1) |
22 |
| -ax2.set_ylabel('(y1, 1)') |
| 18 | +ax2.fill_betweenx(y, x1, 1) |
| 19 | +ax2.set_ylabel('(x1, 1)') |
23 | 20 |
|
24 |
| -ax3.fill_betweenx(x, y1, y2) |
25 |
| -ax3.set_ylabel('(y1, y2)') |
| 21 | +ax3.fill_betweenx(y, x1, x2) |
| 22 | +ax3.set_ylabel('(x1, x2)') |
26 | 23 | ax3.set_xlabel('x')
|
27 | 24 |
|
28 |
| -# now fill between y1 and y2 where a logical condition is met. Note |
| 25 | +# now fill between x1 and x2 where a logical condition is met. Note |
29 | 26 | # this is different than calling
|
30 |
| -# fill_between(x[where], y1[where],y2[where] |
| 27 | +# fill_between(y[where], x1[where], x2[where]) |
31 | 28 | # because of edge effects over multiple contiguous regions.
|
| 29 | + |
32 | 30 | fig = figure()
|
33 | 31 | ax = fig.add_subplot(211)
|
34 |
| -ax.plot(y1, x, y2, x, color='black') |
35 |
| -ax.fill_betweenx(x, y1, y2, where=y2 >= y1, facecolor='green') |
36 |
| -ax.fill_betweenx(x, y1, y2, where=y2 <= y1, facecolor='red') |
| 32 | +ax.plot(x1, y, x2, y, color='black') |
| 33 | +ax.fill_betweenx(y, x1, x2, where=x2 >= x1, facecolor='green') |
| 34 | +ax.fill_betweenx(y, x1, x2, where=x2 <= x1, facecolor='red') |
37 | 35 | ax.set_title('fill between where')
|
38 | 36 |
|
39 | 37 | # Test support for masked arrays.
|
40 |
| -y2 = np.ma.masked_greater(y2, 1.0) |
| 38 | +x2 = np.ma.masked_greater(x2, 1.0) |
41 | 39 | ax1 = fig.add_subplot(212, sharex=ax)
|
42 |
| -ax1.plot(y1, x, y2, x, color='black') |
43 |
| -ax1.fill_betweenx(x, y1, y2, where=y2 >= y1, facecolor='green') |
44 |
| -ax1.fill_betweenx(x, y1, y2, where=y2 <= y1, facecolor='red') |
45 |
| -ax1.set_title('Now regions with y2 > 1 are masked') |
| 40 | +ax1.plot(x1, y, x2, y, color='black') |
| 41 | +ax1.fill_betweenx(y, x1, x2, where=x2 >= x1, facecolor='green') |
| 42 | +ax1.fill_betweenx(y, x1, x2, where=x2 <= x1, facecolor='red') |
| 43 | +ax1.set_title('Now regions with x2 > 1 are masked') |
46 | 44 |
|
47 | 45 | # This example illustrates a problem; because of the data
|
48 | 46 | # gridding, there are undesired unfilled triangles at the crossover
|
|
0 commit comments