2
2
=====================
3
3
Simple Axes Divider 1
4
4
=====================
5
+
6
+ See also :doc:`/tutorials/toolkits/axes_grid`.
5
7
"""
6
8
7
9
from mpl_toolkits .axes_grid1 import Size , Divider
@@ -16,51 +18,48 @@ def label_axes(ax, text):
16
18
left = False , labelleft = False )
17
19
18
20
19
- ##############################################################################
20
- # Fixed axes sizes; fixed paddings.
21
+ fig = plt . figure ( figsize = ( 12 , 6 ))
22
+ sfs = fig . subfigures ( 1 , 2 )
21
23
22
- fig = plt .figure (figsize = (6 , 6 ))
23
- fig .suptitle ("Fixed axes sizes, fixed paddings" )
24
24
25
+ sfs [0 ].suptitle ("Fixed axes sizes, fixed paddings" )
25
26
# Sizes are in inches.
26
27
horiz = [Size .Fixed (1. ), Size .Fixed (.5 ), Size .Fixed (1.5 ), Size .Fixed (.5 )]
27
28
vert = [Size .Fixed (1.5 ), Size .Fixed (.5 ), Size .Fixed (1. )]
28
29
29
30
rect = (0.1 , 0.1 , 0.8 , 0.8 )
30
31
# Divide the axes rectangle into a grid with sizes specified by horiz * vert.
31
- divider = Divider (fig , rect , horiz , vert , aspect = False )
32
+ div = Divider (sfs [ 0 ] , rect , horiz , vert , aspect = False )
32
33
33
34
# The rect parameter will actually be ignored and overridden by axes_locator.
34
- ax1 = fig .add_axes (rect , axes_locator = divider .new_locator (nx = 0 , ny = 0 ))
35
+ ax1 = sfs [ 0 ] .add_axes (rect , axes_locator = div .new_locator (nx = 0 , ny = 0 ))
35
36
label_axes (ax1 , "nx=0, ny=0" )
36
- ax2 = fig .add_axes (rect , axes_locator = divider .new_locator (nx = 0 , ny = 2 ))
37
+ ax2 = sfs [ 0 ] .add_axes (rect , axes_locator = div .new_locator (nx = 0 , ny = 2 ))
37
38
label_axes (ax2 , "nx=0, ny=2" )
38
- ax3 = fig .add_axes (rect , axes_locator = divider .new_locator (nx = 2 , ny = 2 ))
39
+ ax3 = sfs [ 0 ] .add_axes (rect , axes_locator = div .new_locator (nx = 2 , ny = 2 ))
39
40
label_axes (ax3 , "nx=2, ny=2" )
40
- ax4 = fig .add_axes (rect , axes_locator = divider .new_locator (nx = 2 , nx1 = 4 , ny = 0 ))
41
+ ax4 = sfs [ 0 ] .add_axes (rect , axes_locator = div .new_locator (nx = 2 , nx1 = 4 , ny = 0 ))
41
42
label_axes (ax4 , "nx=2, nx1=4, ny=0" )
42
43
43
- ##############################################################################
44
- # Axes sizes that scale with the figure size; fixed paddings.
45
-
46
- fig = plt .figure (figsize = (6 , 6 ))
47
- fig .suptitle ("Scalable axes sizes, fixed paddings" )
48
44
45
+ sfs [1 ].suptitle ("Scalable axes sizes, fixed paddings" )
46
+ # Fixed sizes are in inches, scaled sizes are relative.
49
47
horiz = [Size .Scaled (1.5 ), Size .Fixed (.5 ), Size .Scaled (1. ), Size .Scaled (.5 )]
50
48
vert = [Size .Scaled (1. ), Size .Fixed (.5 ), Size .Scaled (1.5 )]
51
49
52
50
rect = (0.1 , 0.1 , 0.8 , 0.8 )
53
51
# Divide the axes rectangle into a grid with sizes specified by horiz * vert.
54
- divider = Divider (fig , rect , horiz , vert , aspect = False )
52
+ div = Divider (sfs [ 1 ] , rect , horiz , vert , aspect = False )
55
53
56
54
# The rect parameter will actually be ignored and overridden by axes_locator.
57
- ax1 = fig .add_axes (rect , axes_locator = divider .new_locator (nx = 0 , ny = 0 ))
55
+ ax1 = sfs [ 1 ] .add_axes (rect , axes_locator = div .new_locator (nx = 0 , ny = 0 ))
58
56
label_axes (ax1 , "nx=0, ny=0" )
59
- ax2 = fig .add_axes (rect , axes_locator = divider .new_locator (nx = 0 , ny = 2 ))
57
+ ax2 = sfs [ 1 ] .add_axes (rect , axes_locator = div .new_locator (nx = 0 , ny = 2 ))
60
58
label_axes (ax2 , "nx=0, ny=2" )
61
- ax3 = fig .add_axes (rect , axes_locator = divider .new_locator (nx = 2 , ny = 2 ))
59
+ ax3 = sfs [ 1 ] .add_axes (rect , axes_locator = div .new_locator (nx = 2 , ny = 2 ))
62
60
label_axes (ax3 , "nx=2, ny=2" )
63
- ax4 = fig .add_axes (rect , axes_locator = divider .new_locator (nx = 2 , nx1 = 4 , ny = 0 ))
61
+ ax4 = sfs [ 1 ] .add_axes (rect , axes_locator = div .new_locator (nx = 2 , nx1 = 4 , ny = 0 ))
64
62
label_axes (ax4 , "nx=2, nx1=4, ny=0" )
65
63
64
+
66
65
plt .show ()
0 commit comments