|
7 | 7 | import matplotlib.pyplot as plt
|
8 | 8 | import numpy as np
|
9 | 9 |
|
10 |
| -plt.figure(figsize=(7, 4)) |
11 |
| -ax = plt.subplot(121) |
12 |
| -ax.set_aspect(1) |
13 |
| -plt.plot(np.arange(10)) |
14 |
| -plt.xlabel('this is a xlabel\n(with newlines!)') |
15 |
| -plt.ylabel('this is vertical\ntest', multialignment='center') |
16 |
| -plt.text(2, 7, 'this is\nyet another test', |
| 10 | +fig, (ax0, ax1) = plt.subplots(ncols=2, figsize=(7, 4)) |
| 11 | + |
| 12 | +ax0.set_aspect(1) |
| 13 | +ax0.plot(np.arange(10)) |
| 14 | +ax0.set_xlabel('this is a xlabel\n(with newlines!)') |
| 15 | +ax0.set_ylabel('this is vertical\ntest', multialignment='center') |
| 16 | +ax0.text(2, 7, 'this is\nyet another test', |
17 | 17 | rotation=45,
|
18 | 18 | horizontalalignment='center',
|
19 | 19 | verticalalignment='top',
|
20 | 20 | multialignment='center')
|
21 | 21 |
|
22 |
| -plt.grid(True) |
| 22 | +ax0.grid() |
23 | 23 |
|
24 |
| -plt.subplot(122) |
25 | 24 |
|
26 |
| -plt.text(0.29, 0.4, "Mat\nTTp\n123", size=18, |
| 25 | +ax1.text(0.29, 0.4, "Mat\nTTp\n123", size=18, |
27 | 26 | va="baseline", ha="right", multialignment="left",
|
28 | 27 | bbox=dict(fc="none"))
|
29 | 28 |
|
30 |
| -plt.text(0.34, 0.4, "Mag\nTTT\n123", size=18, |
| 29 | +ax1.text(0.34, 0.4, "Mag\nTTT\n123", size=18, |
31 | 30 | va="baseline", ha="left", multialignment="left",
|
32 | 31 | bbox=dict(fc="none"))
|
33 | 32 |
|
34 |
| -plt.text(0.95, 0.4, "Mag\nTTT$^{A^A}$\n123", size=18, |
| 33 | +ax1.text(0.95, 0.4, "Mag\nTTT$^{A^A}$\n123", size=18, |
35 | 34 | va="baseline", ha="right", multialignment="left",
|
36 | 35 | bbox=dict(fc="none"))
|
37 | 36 |
|
38 |
| -plt.xticks([0.2, 0.4, 0.6, 0.8, 1.], |
39 |
| - ["Jan\n2009", "Feb\n2009", "Mar\n2009", "Apr\n2009", "May\n2009"]) |
| 37 | +ax1.set_xticks([0.2, 0.4, 0.6, 0.8, 1.]) |
| 38 | +ax1.set_xticklabels(["Jan\n2009", "Feb\n2009", "Mar\n2009", "Apr\n2009", |
| 39 | + "May\n2009"]) |
40 | 40 |
|
41 |
| -plt.axhline(0.4) |
42 |
| -plt.title("test line spacing for multiline text") |
| 41 | +ax1.axhline(0.4) |
| 42 | +ax1.set_title("test line spacing for multiline text") |
43 | 43 |
|
44 |
| -plt.subplots_adjust(bottom=0.25, top=0.75) |
| 44 | +fig.subplots_adjust(bottom=0.25, top=0.75) |
45 | 45 | plt.show()
|
0 commit comments