|
3 | 3 | Axes Demo
|
4 | 4 | =========
|
5 | 5 |
|
6 |
| -Example use of ``plt.axes`` to create inset axes within the main plot axes. |
| 6 | +Example use of ``fig.add_axes`` to create inset axes within the main plot axes. |
7 | 7 | """
|
8 | 8 | import matplotlib.pyplot as plt
|
9 | 9 | import numpy as np
|
|
19 | 19 | x = np.random.randn(len(t))
|
20 | 20 | s = np.convolve(x, r)[:len(x)] * dt # colored noise
|
21 | 21 |
|
22 |
| -# the main axes is subplot(111) by default |
23 |
| -plt.plot(t, s) |
24 |
| -plt.xlim(0, 1) |
25 |
| -plt.ylim(1.1 * np.min(s), 2 * np.max(s)) |
26 |
| -plt.xlabel('time (s)') |
27 |
| -plt.ylabel('current (nA)') |
28 |
| -plt.title('Gaussian colored noise') |
| 22 | +fig, main_ax = plt.subplots() |
| 23 | +main_ax.plot(t, s) |
| 24 | +main_ax.set_xlim(0, 1) |
| 25 | +main_ax.set_ylim(1.1 * np.min(s), 2 * np.max(s)) |
| 26 | +main_ax.set_xlabel('time (s)') |
| 27 | +main_ax.set_ylabel('current (nA)') |
| 28 | +main_ax.set_title('Gaussian colored noise') |
29 | 29 |
|
30 | 30 | # this is an inset axes over the main axes
|
31 |
| -a = plt.axes([.65, .6, .2, .2], facecolor='k') |
32 |
| -n, bins, patches = plt.hist(s, 400, density=True) |
33 |
| -plt.title('Probability') |
34 |
| -plt.xticks([]) |
35 |
| -plt.yticks([]) |
| 31 | +right_inset_ax = fig.add_axes([.65, .6, .2, .2], facecolor='k') |
| 32 | +right_inset_ax.hist(s, 400, density=True) |
| 33 | +right_inset_ax.set_title('Probability') |
| 34 | +right_inset_ax.set_xticks([]) |
| 35 | +right_inset_ax.set_yticks([]) |
36 | 36 |
|
37 | 37 | # this is another inset axes over the main axes
|
38 |
| -a = plt.axes([0.2, 0.6, .2, .2], facecolor='k') |
39 |
| -plt.plot(t[:len(r)], r) |
40 |
| -plt.title('Impulse response') |
41 |
| -plt.xlim(0, 0.2) |
42 |
| -plt.xticks([]) |
43 |
| -plt.yticks([]) |
| 38 | +left_inset_ax = fig.add_axes([.2, .6, .2, .2], facecolor='k') |
| 39 | +left_inset_ax.plot(t[:len(r)], r) |
| 40 | +left_inset_ax.set_title('Impulse response') |
| 41 | +left_inset_ax.set_xlim(0, 0.2) |
| 42 | +left_inset_ax.set_xticks([]) |
| 43 | +left_inset_ax.set_yticks([]) |
44 | 44 |
|
45 | 45 | plt.show()
|
0 commit comments