Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9cac49d

Browse files
committed
Merge pull request #6247 from simongibbons/fillbetweenx_clarification
DOC: Clarify fillbetween_x example.
2 parents c03262a + 8a02b77 commit 9cac49d

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

examples/pylab_examples/fill_betweenx_demo.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,46 @@
1-
"""
2-
Copy of fill_between.py but using fill_betweenx() instead.
3-
"""
41
import matplotlib.mlab as mlab
52
from matplotlib.pyplot import figure, show
63
import numpy as np
74

85

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)
129

1310
fig = figure()
1411
ax1 = fig.add_subplot(311)
1512
ax2 = fig.add_subplot(312, sharex=ax1)
1613
ax3 = fig.add_subplot(313, sharex=ax1)
1714

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)')
2017

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)')
2320

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)')
2623
ax3.set_xlabel('x')
2724

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
2926
# this is different than calling
30-
# fill_between(x[where], y1[where],y2[where]
27+
# fill_between(y[where], x1[where], x2[where])
3128
# because of edge effects over multiple contiguous regions.
29+
3230
fig = figure()
3331
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')
3735
ax.set_title('fill between where')
3836

3937
# Test support for masked arrays.
40-
y2 = np.ma.masked_greater(y2, 1.0)
38+
x2 = np.ma.masked_greater(x2, 1.0)
4139
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')
4644

4745
# This example illustrates a problem; because of the data
4846
# gridding, there are undesired unfilled triangles at the crossover

0 commit comments

Comments
 (0)