|
5 | 5 |
|
6 | 6 | Demo fill plot.
|
7 | 7 | """
|
8 |
| -import numpy as np |
9 |
| -import matplotlib.pyplot as plt |
10 |
| - |
11 |
| -x = np.linspace(0, 1, 500) |
12 |
| -y = np.sin(4 * np.pi * x) * np.exp(-5 * x) |
13 | 8 |
|
14 | 9 | ###############################################################################
|
15 | 10 | # First, the most basic fill plot a user can make with matplotlib:
|
| 11 | +import numpy as np |
| 12 | +import matplotlib.pyplot as plt |
16 | 13 |
|
17 |
| -fig, ax = plt.subplots() |
18 |
| - |
19 |
| -ax.fill(x, y, zorder=10) |
20 |
| -ax.grid(True, zorder=5) |
| 14 | +x = [0, 1, 2, 1] |
| 15 | +y = [1, 2, 1, 0] |
21 | 16 |
|
22 |
| -x = np.linspace(0, 2 * np.pi, 500) |
23 |
| -y1 = np.sin(x) |
24 |
| -y2 = np.sin(3 * x) |
| 17 | +fig, ax = plt.subplots() |
| 18 | +ax.fill(x, y) |
| 19 | +plt.show() |
25 | 20 |
|
26 | 21 | ###############################################################################
|
27 | 22 | # Next, a few more optional features:
|
|
30 | 25 | # * Setting the fill color.
|
31 | 26 | # * Setting the opacity (alpha value).
|
32 | 27 |
|
| 28 | + |
| 29 | +x = np.linspace(0, 1.5 * np.pi, 500) |
| 30 | +y1 = np.sin(x) |
| 31 | +y2 = np.sin(3 * x) |
| 32 | + |
33 | 33 | fig, ax = plt.subplots()
|
| 34 | + |
34 | 35 | ax.fill(x, y1, 'b', x, y2, 'r', alpha=0.3)
|
| 36 | + |
| 37 | +# Outline of the region we've filled in |
| 38 | +ax.plot(x, y1, c='b', alpha=0.8) |
| 39 | +ax.plot(x, y2, c='r', alpha=0.8) |
| 40 | +ax.plot([x[0], x[-1]], [y1[0], y1[-1]], c='b', alpha=0.8) |
| 41 | +ax.plot([x[0], x[-1]], [y2[0], y2[-1]], c='r', alpha=0.8) |
| 42 | + |
35 | 43 | plt.show()
|
0 commit comments