|
3 | 3 | Axis Equal Demo |
4 | 4 | =============== |
5 | 5 |
|
6 | | -This example is only interesting when run in interactive mode. |
7 | | -
|
8 | 6 | """ |
9 | 7 |
|
10 | | - |
11 | 8 | import matplotlib.pyplot as plt |
12 | 9 | import numpy as np |
13 | 10 |
|
14 | | -# Plot circle or radius 3 |
| 11 | +# Plot circle of radius 3. |
15 | 12 |
|
16 | 13 | an = np.linspace(0, 2*np.pi, 100) |
| 14 | +fig, axs = plt.subplots(2, 2) |
| 15 | + |
| 16 | +axs[0, 0].plot(3*np.cos(an), 3*np.sin(an)) |
| 17 | +axs[0, 0].set_title('not equal, looks like ellipse', fontsize=10) |
| 18 | + |
| 19 | +axs[0, 1].plot(3*np.cos(an), 3*np.sin(an)) |
| 20 | +axs[0, 1].axis('equal') |
| 21 | +axs[0, 1].set_title('equal, looks like circle', fontsize=10) |
| 22 | + |
| 23 | +axs[1, 0].plot(3*np.cos(an), 3*np.sin(an)) |
| 24 | +axs[1, 0].axis('equal') |
| 25 | +axs[1, 0].axis([-3, 3, -3, 3]) |
| 26 | +axs[1, 0].set_title('still a circle, even after changing limits', fontsize=10) |
| 27 | + |
| 28 | +axs[1, 1].plot(3*np.cos(an), 3*np.sin(an)) |
| 29 | +axs[1, 1].set_aspect('equal', 'box') |
| 30 | +axs[1, 1].set_title('still a circle, auto-adjusted data limits', fontsize=10) |
17 | 31 |
|
18 | | -plt.subplot(221) |
19 | | -plt.plot(3*np.cos(an), 3*np.sin(an)) |
20 | | -plt.title('not equal, looks like ellipse', fontsize=10) |
21 | | - |
22 | | -plt.subplot(222) |
23 | | -plt.plot(3*np.cos(an), 3*np.sin(an)) |
24 | | -plt.axis('equal') |
25 | | -plt.title('equal, looks like circle', fontsize=10) |
26 | | - |
27 | | -plt.subplot(223) |
28 | | -plt.plot(3*np.cos(an), 3*np.sin(an)) |
29 | | -plt.axis('equal') |
30 | | -plt.axis([-3, 3, -3, 3]) |
31 | | -plt.title('looks like circle, even after changing limits', fontsize=10) |
32 | | - |
33 | | -plt.subplot(224) |
34 | | -plt.plot(3*np.cos(an), 3*np.sin(an)) |
35 | | -plt.axis('equal') |
36 | | -plt.axis([-3, 3, -3, 3]) |
37 | | -plt.plot([0, 4], [0, 4]) |
38 | | -plt.title('still equal after adding line', fontsize=10) |
39 | | - |
40 | | -plt.tight_layout() |
| 32 | +fig.tight_layout() |
41 | 33 |
|
42 | 34 | plt.show() |
0 commit comments