|
15 | 15 | from basic_units import cm, inch
|
16 | 16 | import matplotlib.pyplot as plt
|
17 | 17 |
|
18 |
| - |
19 | 18 | cms = cm * np.arange(0, 10, 2)
|
20 |
| -bottom = 0*cm |
21 |
| -width = 0.8*cm |
| 19 | +bottom = 0 * cm |
| 20 | +width = 0.8 * cm |
22 | 21 |
|
23 |
| -fig = plt.figure() |
| 22 | +fig, axs = plt.subplots(2, 2) |
24 | 23 |
|
25 |
| -ax1 = fig.add_subplot(2, 2, 1) |
26 |
| -ax1.bar(cms, cms, bottom=bottom) |
| 24 | +axs[0, 0].bar(cms, cms, bottom=bottom) |
27 | 25 |
|
28 |
| -ax2 = fig.add_subplot(2, 2, 2) |
29 |
| -ax2.bar(cms, cms, bottom=bottom, width=width, xunits=cm, yunits=inch) |
| 26 | +axs[0, 1].bar(cms, cms, bottom=bottom, width=width, xunits=cm, yunits=inch) |
30 | 27 |
|
31 |
| -ax3 = fig.add_subplot(2, 2, 3) |
32 |
| -ax3.bar(cms, cms, bottom=bottom, width=width, xunits=inch, yunits=cm) |
33 |
| -ax3.set_xlim(2, 6) # scalars are interpreted in current units |
| 28 | +axs[1, 0].bar(cms, cms, bottom=bottom, width=width, xunits=inch, yunits=cm) |
| 29 | +axs[1, 0].set_xlim(2, 6) # scalars are interpreted in current units |
34 | 30 |
|
35 |
| -ax4 = fig.add_subplot(2, 2, 4) |
36 |
| -ax4.bar(cms, cms, bottom=bottom, width=width, xunits=inch, yunits=inch) |
37 |
| -# fig.savefig('simple_conversion_plot.png') |
38 |
| -ax4.set_xlim(2*cm, 6*cm) # cm are converted to inches |
| 31 | +axs[1, 1].bar(cms, cms, bottom=bottom, width=width, xunits=inch, yunits=inch) |
| 32 | +axs[1, 1].set_xlim(2 * cm, 6 * cm) # cm are converted to inches |
39 | 33 |
|
| 34 | +fig.tight_layout() |
40 | 35 | plt.show()
|
0 commit comments