@@ -26,35 +26,21 @@ def demo_simple_image(ax):
26
26
27
27
28
28
def demo_locatable_axes_hard (fig ):
29
-
30
29
from mpl_toolkits .axes_grid1 import Size , SubplotDivider
31
- from mpl_toolkits .axes_grid1 .mpl_axes import Axes
32
30
33
31
divider = SubplotDivider (fig , 2 , 2 , 2 , aspect = True )
34
32
35
33
# 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 ))
38
35
# 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 ))
52
37
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 )])
58
44
59
45
Z , extent = get_demo_image ()
60
46
@@ -96,7 +82,6 @@ def demo_images_side_by_side(ax):
96
82
97
83
98
84
def demo ():
99
-
100
85
fig = plt .figure (figsize = (6 , 6 ))
101
86
102
87
# PLOT 1
@@ -105,21 +90,16 @@ def demo():
105
90
demo_simple_image (ax )
106
91
107
92
# 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
111
94
demo_locatable_axes_hard (fig )
112
95
113
96
# 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
117
98
ax = fig .add_subplot (2 , 2 , 3 )
118
99
demo_locatable_axes_easy (ax )
119
100
120
101
# PLOT 4
121
102
# two images side by side with fixed padding.
122
-
123
103
ax = fig .add_subplot (2 , 2 , 4 )
124
104
demo_images_side_by_side (ax )
125
105
0 commit comments