|
22 | 22 |
|
23 | 23 | # Two subplots, the axes array is 1-d
|
24 | 24 | f, axarr = plt.subplots(2, sharex=True)
|
| 25 | +f.suptitle('Sharing X axis') |
25 | 26 | axarr[0].plot(x, y)
|
26 |
| -axarr[0].set_title('Sharing X axis') |
27 | 27 | axarr[1].scatter(x, y)
|
28 | 28 |
|
29 | 29 | # Two subplots, unpack the axes array immediately
|
30 | 30 | f, (ax1, ax2) = plt.subplots(1, 2, sharey=True)
|
| 31 | +f.suptitle('Sharing Y axis') |
31 | 32 | ax1.plot(x, y)
|
32 |
| -ax1.set_title('Sharing Y axis') |
33 | 33 | ax2.scatter(x, y)
|
34 | 34 |
|
35 | 35 | # Three subplots sharing both x/y axes
|
36 |
| -f, (ax1, ax2, ax3) = plt.subplots(3, sharex=True, sharey=True) |
37 |
| -ax1.plot(x, y) |
38 |
| -ax1.set_title('Sharing both axes') |
39 |
| -ax2.scatter(x, y) |
40 |
| -ax3.scatter(x, 2 * y ** 2 - 1, color='r') |
41 |
| -# Fine-tune figure; make subplots close to each other and hide x ticks for |
42 |
| -# all but bottom plot. |
| 36 | +f, axarr = plt.subplots(3, sharex=True, sharey=True) |
| 37 | +f.suptitle('Sharing both axes') |
| 38 | +axarr[0].plot(x, y) |
| 39 | +axarr[1].scatter(x, y) |
| 40 | +axarr[2].scatter(x,
10000
2 * y ** 2 - 1, color='r') |
| 41 | +# Bring subplots close to each other. |
43 | 42 | f.subplots_adjust(hspace=0)
|
44 |
| -plt.setp([a.get_xticklabels() for a in f.axes[:-1]], visible=False) |
| 43 | +# Hide x labels and tick labels for all but bottom plot. |
| 44 | +for ax in axarr: |
| 45 | + ax.label_outer() |
45 | 46 |
|
46 | 47 | # row and column sharing
|
47 | 48 | f, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, sharex='col', sharey='row')
|
| 49 | +f.suptitle('Sharing x per column, y per row') |
48 | 50 | ax1.plot(x, y)
|
49 |
| -ax1.set_title('Sharing x per column, y per row') |
50 | 51 | ax2.scatter(x, y)
|
51 | 52 | ax3.scatter(x, 2 * y ** 2 - 1, color='r')
|
52 | 53 | ax4.plot(x, 2 * y ** 2 - 1, color='r')
|
|
61 | 62 | axarr[1, 0].set_title('Axis [1,0]')
|
62 | 63 | axarr[1, 1].scatter(x, y ** 2)
|
63 | 64 | axarr[1, 1].set_title('Axis [1,1]')
|
64 |
| -# Fine-tune figure; hide x ticks for top plots and y ticks for right plots |
65 |
| -plt.setp([a.get_xticklabels() for a in axarr[0, :]], visible=False) |
66 |
| -plt.setp([a.get_yticklabels() for a in axarr[:, 1]], visible=False) |
| 65 | +for ax in axarr.flat: |
| 66 | + ax.set(xlabel='x-label', ylabel='y-label') |
| 67 | +# Hide x labels and tick labels for top plots and y ticks for right plots. |
| 68 | +for ax in axarr.flat: |
| 69 | + ax.label_outer() |
67 | 70 |
|
68 | 71 | # Four polar axes
|
69 | 72 | f, axarr = plt.subplots(2, 2, subplot_kw=dict(projection='polar'))
|
|
0 commit comments