|
4 | 4 | =====================
|
5 | 5 |
|
6 | 6 | """
|
| 7 | + |
7 | 8 | from mpl_toolkits.axes_grid1 import Size, Divider
|
8 | 9 | import matplotlib.pyplot as plt
|
9 | 10 |
|
10 | 11 |
|
11 |
| -fig1 = plt.figure(1, (6, 6)) |
| 12 | +############################################################################## |
| 13 | +# Fixed axes sizes; fixed paddings. |
| 14 | + |
| 15 | +fig = plt.figure(figsize=(6, 6)) |
12 | 16 |
|
13 |
| -# fixed size in inch |
14 |
| -horiz = [Size.Fixed(1.), Size.Fixed(.5), Size.Fixed(1.5), |
15 |
| - Size.Fixed(.5)] |
| 17 | +# Sizes are in inches. |
| 18 | +horiz = [Size.Fixed(1.), Size.Fixed(.5), Size.Fixed(1.5), Size.Fixed(.5)] |
16 | 19 | vert = [Size.Fixed(1.5), Size.Fixed(.5), Size.Fixed(1.)]
|
17 | 20 |
|
18 | 21 | rect = (0.1, 0.1, 0.8, 0.8)
|
19 |
| -# divide the axes rectangle into grid whose size is specified by horiz * vert |
20 |
| -divider = Divider(fig1, rect, horiz, vert, aspect=False) |
21 |
| - |
22 |
| -# the rect parameter will be ignore as we will set axes_locator |
23 |
| -ax1 = fig1.add_axes(rect, label="1") |
24 |
| -ax2 = fig1.add_axes(rect, label="2") |
25 |
| -ax3 = fig1.add_axes(rect, label="3") |
26 |
| -ax4 = fig1.add_axes(rect, label="4") |
27 |
| - |
28 |
| -ax1.set_axes_locator(divider.new_locator(nx=0, ny=0)) |
29 |
| -ax2.set_axes_locator(divider.new_locator(nx=0, ny=2)) |
30 |
| -ax3.set_axes_locator(divider.new_locator(nx=2, ny=2)) |
31 |
| -ax4.set_axes_locator(divider.new_locator(nx=2, nx1=4, ny=0)) |
| 22 | +# Divide the axes rectangle into a grid with sizes specified by horiz * vert. |
| 23 | +divider = Divider(fig, rect, horiz, vert, aspect=False) |
| 24 | + |
| 25 | +# The rect parameter will actually be ignored and overridden by axes_locator. |
| 26 | +ax1 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=0)) |
| 27 | +ax2 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=2)) |
| 28 | +ax3 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, ny=2)) |
| 29 | +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) |
| 33 | + |
| 34 | +############################################################################## |
| 35 | +# Axes sizes that scale with the figure size; fixed paddings. |
| 36 | + |
| 37 | +fig = plt.figure(figsize=(6, 6)) |
| 38 | + |
| 39 | +horiz = [Size.Scaled(1.5), Size.Fixed(.5), Size.Scaled(1.), Size.Scaled(.5)] |
| 40 | +vert = [Size.Scaled(1.), Size.Fixed(.5), Size.Scaled(1.5)] |
| 41 | + |
| 42 | +rect = (0.1, 0.1, 0.8, 0.8) |
| 43 | +# Divide the axes rectangle into a grid with sizes specified by horiz * vert. |
| 44 | +divider = Divider(fig, rect, horiz, vert, aspect=False) |
| 45 | + |
| 46 | +# The rect parameter will actually be ignored and overridden by axes_locator. |
| 47 | +ax1 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=0)) |
| 48 | +ax2 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=2)) |
| 49 | +ax3 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, ny=2)) |
| 50 | +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) |
32 | 54 |
|
33 | 55 | plt.show()
|
0 commit comments