@@ -14,7 +14,7 @@ def demo_simple_grid(fig):
14
14
A grid of 2x2 images with 0.05 inch pad between images and only
15
15
the lower-left axes is labeled.
16
16
"""
17
- grid = AxesGrid (fig , 131 , # similar to subplot(131 )
17
+ grid = AxesGrid (fig , 141 , # similar to subplot(141 )
18
18
nrows_ncols = (2 , 2 ),
19
19
axes_pad = 0.05 ,
20
20
label_mode = "1" ,
@@ -33,7 +33,7 @@ def demo_grid_with_single_cbar(fig):
33
33
"""
34
34
A grid of 2x2 images with a single colorbar
35
35
"""
36
- grid = AxesGrid (fig , 132 , # similar to subplot(132 )
36
+ grid = AxesGrid (fig , 142 , # similar to subplot(142 )
37
37
nrows_ncols = (2 , 2 ),
38
38
axes_pad = 0.0 ,
39
39
share_all = True ,
@@ -61,7 +61,7 @@ def demo_grid_with_each_cbar(fig):
61
61
A grid of 2x2 images. Each image has its own colorbar.
62
62
"""
63
63
64
- grid = AxesGrid (F , 133 , # similar to subplot(122 )
64
+ grid = AxesGrid (F , 143 , # similar to subplot(143 )
65
65
nrows_ncols = (2 , 2 ),
66
66
axes_pad = 0.1 ,
67
67
label_mode = "1" ,
@@ -83,16 +83,47 @@ def demo_grid_with_each_cbar(fig):
83
83
grid .axes_llc .set_xticks ([- 2 , 0 , 2 ])
84
84
grid .axes_llc .set_yticks ([- 2 , 0 , 2 ])
85
85
86
+ def demo_grid_with_each_cbar_labelled (fig ):
87
+ """
88
+ A grid of 2x2 images. Each image has its own colorbar.
89
+ """
90
+
91
+ grid = AxesGrid (F , 144 , # similar to subplot(144)
92
+ nrows_ncols = (2 , 2 ),
93
+ axes_pad = ( 0.45 , 0.15 ),
94
+ label_mode = "1" ,
95
+ share_all = True ,
96
+ cbar_location = "right" ,
97
+ cbar_mode = "each" ,
98
+ cbar_size = "7%" ,
99
+ cbar_pad = "2%" ,
100
+ )
101
+ Z , extent = get_demo_image ()
102
+
103
+ # Use a different colorbar range every time
104
+ limits = ((0 , 1 ), (- 2 , 2 ), (- 1.7 , 1.4 ), (- 1.5 , 1 ))
105
+ for i in range (4 ):
106
+ im = grid [i ].imshow (Z , extent = extent , interpolation = "nearest" ,
107
+ vmin = limits [i ][0 ], vmax = limits [i ][1 ])
108
+ grid .cbar_axes [i ].colorbar (im )
109
+
110
+ for i , cax in enumerate (grid .cbar_axes ):
111
+ cax .set_yticks ((limits [i ][0 ], limits [i ][1 ]))
112
+
113
+ # This affects all axes because we set share_all = True.
114
+ grid .axes_llc .set_xticks ([- 2 , 0 , 2 ])
115
+ grid .axes_llc .set_yticks ([- 2 , 0 , 2 ])
86
116
87
117
88
118
if 1 :
89
- F = plt .figure (1 , (5 .5 , 2.5 ))
119
+ F = plt .figure (1 , (10 .5 , 2.5 ))
90
120
91
- F .subplots_adjust (left = 0.05 , right = 0.98 )
121
+ F .subplots_adjust (left = 0.05 , right = 0.95 )
92
122
93
123
demo_simple_grid (F )
94
124
demo_grid_with_single_cbar (F )
95
125
demo_grid_with_each_cbar (F )
126
+ demo_grid_with_each_cbar_labelled (F )
96
127
97
128
plt .draw ()
98
129
plt .show ()
0 commit comments