|
4 | 4 | ================= |
5 | 5 |
|
6 | 6 | Simple demo with multiple subplots. |
| 7 | +
|
| 8 | +For more options, see :doc:`/gallery/subplots_axes_and_figures/subplots_demo`. |
| 9 | +
|
| 10 | +.. redirect-from:: /gallery/subplots_axes_and_figures/subplot_demo |
7 | 11 | """ |
| 12 | + |
8 | 13 | import numpy as np |
9 | 14 | import matplotlib.pyplot as plt |
10 | 15 |
|
11 | | -############################################################################### |
12 | | - |
| 16 | +# Create some fake data. |
13 | 17 | x1 = np.linspace(0.0, 5.0) |
14 | | -x2 = np.linspace(0.0, 2.0) |
15 | | - |
16 | 18 | y1 = np.cos(2 * np.pi * x1) * np.exp(-x1) |
| 19 | +x2 = np.linspace(0.0, 2.0) |
17 | 20 | y2 = np.cos(2 * np.pi * x2) |
18 | 21 |
|
| 22 | +############################################################################### |
| 23 | +# `~.pyplot.subplots()` is the recommended method to generate simple subplot |
| 24 | +# arrangements: |
| 25 | + |
19 | 26 | fig, (ax1, ax2) = plt.subplots(2, 1) |
20 | 27 | fig.suptitle('A tale of 2 subplots') |
21 | 28 |
|
|
28 | 35 |
|
29 | 36 | plt.show() |
30 | 37 |
|
31 | | -############################################################################# |
32 | | -# |
33 | | -# |
34 | | -# Alternative Method For Creating Multiple Plots |
35 | | -# """""""""""""""""""""""""""""""""""""""""""""" |
36 | | -# |
37 | | -# Subplots can also be generated using `~.pyplot.subplot()` \ |
38 | | -# as in the following example: |
39 | | -# |
40 | | - |
41 | | - |
42 | | -x1 = np.linspace(0.0, 5.0) |
43 | | -x2 = np.linspace(0.0, 2.0) |
44 | | - |
45 | | -y1 = np.cos(2 * np.pi * x1) * np.exp(-x1) |
46 | | -y2 = np.cos(2 * np.pi * x2) |
| 38 | +############################################################################### |
| 39 | +# Subplots can also be generated one at a time using `~.pyplot.subplot()`: |
47 | 40 |
|
48 | 41 | plt.subplot(2, 1, 1) |
49 | 42 | plt.plot(x1, y1, 'o-') |
|
0 commit comments