|
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 | +
|
| 8 | +Please see also the :ref:`axes_grid_examples` section, and the following three |
| 9 | +examples: |
| 10 | +
|
| 11 | + - :doc:`/gallery/subplots_axes_and_figures/zoom_inset_axes` |
| 12 | + - :doc:`/gallery/axes_grid1/inset_locator_demo` |
| 13 | + - :doc:`/gallery/axes_grid1/inset_locator_demo2` |
7 | 14 | """
|
8 | 15 | import matplotlib.pyplot as plt
|
9 | 16 | import numpy as np
|
|
19 | 26 | x = np.random.randn(len(t))
|
20 | 27 | s = np.convolve(x, r)[:len(x)] * dt # colored noise
|
21 | 28 |
|
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') |
| 29 | +fig, main_ax = plt.subplots() |
| 30 | +main_ax.plot(t, s) |
| 31 | +main_ax.set_xlim(0, 1) |
| 32 | +main_ax.set_ylim(1.1 * np.min(s), 2 * np.max(s)) |
| 33 | +main_ax.set_xlabel('time (s)') |
| 34 | +main_ax.set_ylabel('current (nA)') |
| 35 | +main_ax.set_title('Gaussian colored noise') |
29 | 36 |
|
30 | 37 | # 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([]) |
| 38 | +right_inset_ax = fig.add_axes([.65, .6, .2, .2], facecolor='k') |
| 39 | +right_inset_ax.hist(s, 400, density=True) |
| 40 | +right_inset_ax.set_title('Probability') |
| 41 | +right_inset_ax.set_xticks([]) |
| 42 | +right_inset_ax.set_yticks([]) |
36 | 43 |
|
37 | 44 | # 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([]) |
| 45 | +left_inset_ax = fig.add_axes([.2, .6, .2, .2], facecolor='k') |
| 46 | +left_inset_ax.plot(t[:len(r)], r) |
| 47 | +left_inset_ax.set_title('Impulse response') |
| 48 | +left_inset_ax.set_xlim(0, 0.2) |
| 49 | +left_inset_ax.set_xticks([]) |
| 50 | +left_inset_ax.set_yticks([]) |
44 | 51 |
|
45 | 52 | plt.show()
|
0 commit comments