|
3 | 3 | Fill Betweenx Demo
|
4 | 4 | ==================
|
5 | 5 |
|
6 |
| -Using ``fill_betweenx`` to color between two horizontal curves. |
| 6 | +Using `~.Axes.fill_betweenx` to color along the horizontal direction between |
| 7 | +two curves. |
7 | 8 | """
|
8 | 9 | import matplotlib.pyplot as plt
|
9 | 10 | import numpy as np
|
|
13 | 14 | x1 = np.sin(2 * np.pi * y)
|
14 | 15 | x2 = 1.2 * np.sin(4 * np.pi * y)
|
15 | 16 |
|
16 |
| -fig, [ax1, ax2, ax3] = plt.subplots(3, 1, sharex=True) |
| 17 | +fig, [ax1, ax2, ax3] = plt.subplots(1, 3, sharey=True, figsize=(6, 6)) |
17 | 18 |
|
18 | 19 | ax1.fill_betweenx(y, 0, x1)
|
19 |
| -ax1.set_ylabel('(x1, 0)') |
| 20 | +ax1.set_title('between (x1, 0)') |
20 | 21 |
|
21 | 22 | ax2.fill_betweenx(y, x1, 1)
|
22 |
| -ax2.set_ylabel('(x1, 1)') |
| 23 | +ax2.set_title('between (x1, 1)') |
| 24 | +ax2.set_xlabel('x') |
23 | 25 |
|
24 | 26 | ax3.fill_betweenx(y, x1, x2)
|
25 |
| -ax3.set_ylabel('(x1, x2)') |
26 |
| -ax3.set_xlabel('x') |
| 27 | +ax3.set_title('between (x1, x2)') |
27 | 28 |
|
28 | 29 | # now fill between x1 and x2 where a logical condition is met. Note
|
29 | 30 | # this is different than calling
|
30 | 31 | # fill_between(y[where], x1[where], x2[where])
|
31 | 32 | # because of edge effects over multiple contiguous regions.
|
32 | 33 |
|
33 |
| -fig, [ax, ax1] = plt.subplots(2, 1, sharex=True) |
| 34 | +fig, [ax, ax1] = plt.subplots(1, 2, sharey=True, figsize=(6, 6)) |
34 | 35 | ax.plot(x1, y, x2, y, color='black')
|
35 | 36 | ax.fill_betweenx(y, x1, x2, where=x2 >= x1, facecolor='green')
|
36 | 37 | ax.fill_betweenx(y, x1, x2, where=x2 <= x1, facecolor='red')
|
37 |
| -ax.set_title('fill between where') |
| 38 | +ax.set_title('fill_betweenx where') |
38 | 39 |
|
39 | 40 | # Test support for masked arrays.
|
40 | 41 | x2 = np.ma.masked_greater(x2, 1.0)
|
41 | 42 | ax1.plot(x1, y, x2, y, color='black')
|
42 | 43 | ax1.fill_betweenx(y, x1, x2, where=x2 >= x1, facecolor='green')
|
43 | 44 | ax1.fill_betweenx(y, x1, x2, where=x2 <= x1, facecolor='red')
|
44 |
| -ax1.set_title('Now regions with x2 > 1 are masked') |
| 45 | +ax1.set_title('regions with x2 > 1 are masked') |
45 | 46 |
|
46 | 47 | # This example illustrates a problem; because of the data
|
47 | 48 | # gridding, there are undesired unfilled triangles at the crossover
|
|
0 commit comments