|
2 | 2 | =====================
|
3 | 3 | Simple Axes Divider 1
|
4 | 4 | =====================
|
5 |
| -
|
6 | 5 | """
|
7 | 6 |
|
8 | 7 | from mpl_toolkits.axes_grid1 import Size, Divider
|
9 | 8 | import matplotlib.pyplot as plt
|
10 | 9 |
|
11 | 10 |
|
| 11 | +def label_axes(ax, text): |
| 12 | + """Place a label at the center of an axes, and remove the axis ticks.""" |
| 13 | + ax.text(.5, .5, text, transform=ax.transAxes, |
| 14 | + horizontalalignment="center", verticalalignment="center") |
| 15 | + ax.tick_params(bottom=False, labelbottom=False, |
| 16 | + left=False, labelleft=False) |
| 17 | + |
| 18 | + |
12 | 19 | ##############################################################################
|
13 | 20 | # Fixed axes sizes; fixed paddings.
|
14 | 21 |
|
15 | 22 | fig = plt.figure(figsize=(6, 6))
|
| 23 | +fig.suptitle("Fixed axes sizes, fixed paddings") |
16 | 24 |
|
17 | 25 | # Sizes are in inches.
|
18 | 26 | horiz = [Size.Fixed(1.), Size.Fixed(.5), Size.Fixed(1.5), Size.Fixed(.5)]
|
|
24 | 32 |
|
25 | 33 | # The rect parameter will actually be ignored and overridden by axes_locator.
|
26 | 34 | ax1 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=0))
|
| 35 | +label_axes(ax1, "nx=0, ny=0") |
27 | 36 | ax2 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=2))
|
| 37 | +label_axes(ax2, "nx=0, ny=2") |
28 | 38 | ax3 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, ny=2))
|
| 39 | +label_axes(ax3, "nx=2, ny=2") |
29 | 40 | ax4 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, nx1=4, ny=0))
|
30 |
| - |
31 |
| -for ax in fig.axes: |
32 |
| - ax.tick_params(labelbottom=False, labelleft=False) |
| 41 | +label_axes(ax4, "nx=2, nx1=4, ny=0") |
33 | 42 |
|
34 | 43 | ##############################################################################
|
35 | 44 | # Axes sizes that scale with the figure size; fixed pa
CD8C
ddings.
|
36 | 45 |
|
37 | 46 | fig = plt.figure(figsize=(6, 6))
|
| 47 | +fig.suptitle("Scalable axes sizes, fixed paddings") |
38 | 48 |
|
39 | 49 | horiz = [Size.Scaled(1.5), Size.Fixed(.5), Size.Scaled(1.), Size.Scaled(.5)]
|
40 | 50 | vert = [Size.Scaled(1.), Size.Fixed(.5), Size.Scaled(1.5)]
|
|
45 | 55 |
|
46 | 56 | # The rect parameter will actually be ignored and overridden by axes_locator.
|
47 | 57 | ax1 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=0))
|
| 58 | +label_axes(ax1, "nx=0, ny=0") |
48 | 59 | ax2 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=2))
|
| 60 | +label_axes(ax2, "nx=0, ny=2") |
49 | 61 | ax3 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, ny=2))
|
| 62 | +label_axes(ax3, "nx=2, ny=2") |
50 | 63 | ax4 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, nx1=4, ny=0))
|
51 |
| - |
52 |
| -for ax in fig.axes: |
53 |
| - ax.tick_params(labelbottom=False, labelleft=False) |
| 64 | +label_axes(ax4, "nx=2, nx1=4, ny=0") |
54 | 65 |
|
55 | 66 | plt.show()
|
0 commit comments