@@ -14,7 +14,7 @@ def demo_simple_grid(fig):
1414 A grid of 2x2 images with 0.05 inch pad between images and only
1515 the lower-left axes is labeled.
1616 """
17- grid = AxesGrid (fig , 131 , # similar to subplot(131 )
17+ grid = AxesGrid (fig , 141 , # similar to subplot(141 )
1818 nrows_ncols = (2 , 2 ),
1919 axes_pad = 0.05 ,
2020 label_mode = "1" ,
@@ -33,7 +33,7 @@ def demo_grid_with_single_cbar(fig):
3333 """
3434 A grid of 2x2 images with a single colorbar
3535 """
36- grid = AxesGrid (fig , 132 , # similar to subplot(132 )
36+ grid = AxesGrid (fig , 142 , # similar to subplot(142 )
3737 nrows_ncols = (2 , 2 ),
3838 axes_pad = 0.0 ,
3939 share_all = True ,
@@ -61,7 +61,7 @@ def demo_grid_with_each_cbar(fig):
6161 A grid of 2x2 images. Each image has its own colorbar.
6262 """
6363
64- grid = AxesGrid (F , 133 , # similar to subplot(122 )
64+ grid = AxesGrid (F , 143 , # similar to subplot(143 )
6565 nrows_ncols = (2 , 2 ),
6666 axes_pad = 0.1 ,
6767 label_mode = "1" ,
@@ -83,16 +83,47 @@ def demo_grid_with_each_cbar(fig):
8383 grid .axes_llc .set_xticks ([- 2 , 0 , 2 ])
8484 grid .axes_llc .set_yticks ([- 2 , 0 , 2 ])
8585
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 ])
86116
87117
88118if 1 :
89- F = plt .figure (1 , (5 .5 , 2.5 ))
119+ F = plt .figure (1 , (10 .5 , 2.5 ))
90120
91- F .subplots_adjust (left = 0.05 , right = 0.98 )
121+ F .subplots_adjust (left = 0.05 , right = 0.95 )
92122
93123 demo_simple_grid (F )
94124 demo_grid_with_single_cbar (F )
95125 demo_grid_with_each_cbar (F )
126+ demo_grid_with_each_cbar_labelled (F )
96127
97128 plt .draw ()
98129 plt .show ()
0 commit comments