@@ -26,35 +26,21 @@ def demo_simple_image(ax):
2626
2727
2828def demo_locatable_axes_hard (fig ):
29-
3029 from mpl_toolkits .axes_grid1 import Size , SubplotDivider
31- from mpl_toolkits .axes_grid1 .mpl_axes import Axes
3230
3331 divider = SubplotDivider (fig , 2 , 2 , 2 , aspect = True )
3432
3533 # axes for image
36- ax = fig .add_axes (divider .get_position (), axes_class = Axes )
37-
34+ ax = fig .add_subplot (axes_locator = divider .new_locator (nx = 0 , ny = 0 ))
3835 # axes for colorbar
39- # (the label prevents Axes.add_axes from incorrectly believing that the two
40- # axes are the same)
41- ax_cb = fig .add_axes (divider .get_position (), axes_class = Axes , label = "cb" )
42-
43- h = [Size .AxesX (ax ), # main axes
44- Size .Fixed (0.05 ), # padding, 0.1 inch
45- Size .Fixed (0.2 ), # colorbar, 0.3 inch
46- ]
47-
48- v = [Size .AxesY (ax )]
49-
50- divider .set_horizontal (h )
51- divider .set_vertical (v )
36+ ax_cb = fig .add_subplot (axes_locator = divider .new_locator (nx = 2 , ny = 0 ))
5237
53- ax .set_axes_locator (divider .new_locator (nx = 0 , ny = 0 ))
54- ax_cb .set_axes_locator (divider .new_locator (nx = 2 , ny = 0 ))
55-
56- ax_cb .axis ["left" ].toggle (all = False )
57- ax_cb .axis ["right" ].toggle (ticks = True )
38+ divider .set_horizontal ([
39+ Size .AxesX (ax ), # main axes
40+ Size .Fixed (0.05 ), # padding, 0.1 inch
41+ Size .Fixed (0.2 ), # colorbar, 0.3 inch
42+ ])
43+ divider .set_vertical ([Size .AxesY (ax )])
5844
5945 Z , extent = get_demo_image ()
6046
@@ -96,7 +82,6 @@ def demo_images_side_by_side(ax):
9682
9783
9884def demo ():
99-
10085 fig = plt .figure (figsize = (6 , 6 ))
10186
10287 # PLOT 1
@@ -105,21 +90,16 @@ def demo():
10590 demo_simple_image (ax )
10691
10792 # PLOT 2
108- # image and colorbar whose location is adjusted in the drawing time.
109- # a hard way
110-
93+ # image and colorbar with draw-time positioning -- a hard way
11194 demo_locatable_axes_hard (fig )
11295
11396 # PLOT 3
114- # image and colorbar whose location is adjusted in the drawing time.
115- # an easy way
116-
97+ # image and colorbar with draw-time positioning -- an easy way
11798 ax = fig .add_subplot (2 , 2 , 3 )
11899 demo_locatable_axes_easy (ax )
119100
120101 # PLOT 4
121102 # two images side by side with fixed padding.
122-
123103 ax = fig .add_subplot (2 , 2 , 4 )
124104 demo_images_side_by_side (ax )
125105
0 commit comments