@@ -198,88 +198,15 @@ def example_plot(ax, fontsize=12):
198
198
example_plot (ax1 )
199
199
example_plot (ax2 )
200
200
201
- gs1 .tight_layout (fig , rect = [0 , 0 , 0.5 , 1 ])
201
+ gs1 .tight_layout (fig , rect = [0 , 0 , 0.5 , 1.0 ])
202
202
203
203
###############################################################################
204
- # For example, this can be used for a figure with multiple gridspecs.
204
+ # However, we do not recommend that this be used to manually construct more
205
+ # complicated layouts, like having one GridSpec in the left and one in the
206
+ # right side of the figure. For these use cases, one should instead take
207
+ # advantage of :doc:`/gallery/subplots_axes_and_figures/gridspec_nested`, or
208
+ # the :doc:`/users/next_whats_new/subfigures`.
205
209
206
- fig = plt .figure ()
207
-
208
- gs1 = gridspec .GridSpec (2 , 1 )
209
- ax1 = fig .add_subplot (gs1 [0 ])
210
- ax2 = fig .add_subplot (gs1 [1 ])
211
-
212
- example_plot (ax1 )
213
- example_plot (ax2 )
214
-
215
- gs1 .tight_layout (fig , rect = [0 , 0 , 0.5 , 1 ])
216
-
217
- gs2 = gridspec .GridSpec (3 , 1 )
218
-
219
- for ss in gs2 :
220
- ax = fig .add_subplot (ss )
221
- example_plot (ax )
222
- ax .set_title ("" )
223
- ax .set_xlabel ("" )
224
-
225
- ax .set_xlabel ("x-label" , fontsize = 12 )
226
-
227
- gs2 .tight_layout (fig , rect = [0.5 , 0 , 1 , 1 ], h_pad = 0.5 )
228
-
229
- # We may try to match the top and bottom of two grids ::
230
- top = min (gs1 .top , gs2 .top )
231
- bottom = max (gs1 .bottom , gs2 .bottom )
232
-
233
- gs1 .update (top = top , bottom = bottom )
234
- gs2 .update (top = top , bottom = bottom )
235
- plt .show ()
236
-
237
- ###############################################################################
238
- # While this should be mostly good enough, adjusting top and bottom may
239
- # require adjustment of hspace also. To update hspace & vspace, we call
240
- # `.GridSpec.tight_layout` again with updated rect argument. Note that the
241
- # rect argument specifies the area including the ticklabels, etc. Thus, we
242
- # will increase the bottom (which is 0 for the normal case) by the difference
243
- # between the *bottom* from above and the bottom of each gridspec. Same thing
244
- # for the top.
245
-
246
- fig = plt .gcf ()
247
-
248
- gs1 = gridspec .GridSpec (2 , 1 )
249
- ax1 = fig .add_subplot (gs1 [0 ])
250
- ax2 = fig .add_subplot (gs1 [1 ])
251
-
252
- example_plot (ax1 )
253
- example_plot (ax2 )
254
-
255
- gs1 .tight_layout (fig , rect = [0 , 0 , 0.5 , 1 ])
256
-
257
- gs2 = gridspec .GridSpec (3 , 1 )
258
-
259
- for ss in gs2 :
260
- ax = fig .add_subplot (ss )
261
- example_plot (ax )
262
- ax .set_title ("" )
263
- ax .set_xlabel ("" )
264
-
265
- ax .set_xlabel ("x-label" , fontsize = 12 )
266
-
267
- gs2 .tight_layout (fig , rect = [0.5 , 0 , 1 , 1 ], h_pad = 0.5 )
268
-
269
- top = min (gs1 .top , gs2 .top )
270
- bottom = max (gs1 .bottom , gs2 .bottom )
271
-
272
- gs1 .update (top = top , bottom = bottom )
273
- gs2 .update (top = top , bottom = bottom )
274
-
275
- top = min (gs1 .top , gs2 .top )
276
- bottom = max (gs1 .bottom , gs2 .bottom )
277
-
278
- gs1 .tight_layout (fig , rect = [None , 0 + (bottom - gs1 .bottom ),
279
- 0.5 , 1 - (gs1 .top - top )])
280
- gs2 .tight_layout (fig , rect = [0.5 , 0 + (bottom - gs2 .bottom ),
281
- None , 1 - (gs2 .top - top )],
282
- h_pad = 0.5 )
283
210
284
211
###############################################################################
285
212
# Legends and Annotations
0 commit comments