@@ -133,14 +133,25 @@ def example_plot(ax, fontsize=12, nodec=False):
133
133
134
134
############################################################################
135
135
# If you specify a list of axes (or other iterable container) to the
136
- # ``ax`` argument of ``colorbar``, constrained_layout will take space from all
137
- # axes that share the same gridspec .
136
+ # ``ax`` argument of ``colorbar``, constrained_layout will take space from
137
+ # the specified axes .
138
138
139
139
fig , axs = plt .subplots (2 , 2 , figsize = (4 , 4 ), constrained_layout = True )
140
140
for ax in axs .flatten ():
141
141
im = ax .pcolormesh (arr , ** pc_kwargs )
142
142
fig .colorbar (im , ax = axs , shrink = 0.6 )
143
143
144
+ ############################################################################
145
+ # If you specify a list of axes from inside a grid of axes, the colorbar
146
+ # will steal space appropriately, and leave a gap, but all subplots will
147
+ # still be the same size.
148
+
149
+ fig , axs = plt .subplots (3 , 3 , figsize = (4 , 4 ), constrained_layout = True )
150
+ for ax in axs .flatten ():
151
+ im = ax .pcolormesh (arr , ** pc_kwargs )
152
+ fig .colorbar (im , ax = axs [1 :,][:, 1 ], shrink = 0.8 )
153
+ fig .colorbar (im , ax = axs [:, - 1 ], shrink = 0.6 )
154
+
144
155
############################################################################
145
156
# Note that there is a bit of a subtlety when specifying a single axes
146
157
# as the parent. In the following, it might be desirable and expected
@@ -454,6 +465,21 @@ def docomplicated(suptitle=None):
454
465
bb_ax2 = Bbox (fig_coords_ax2 )
455
466
ax2 = fig .add_axes (bb_ax2 )
456
467
468
+ ###############################################################################
469
+ # Manually turning off ``constrained_layout``
470
+ # ===========================================
471
+ #
472
+ # ``constrained_layout`` usually adjusts the axes positions on each draw
473
+ # of the figure. If you want to get the spacing provided by
474
+ # ``constrained_layout`` but then not have it update, then do the initial
475
+ # draw and then call ``fig.set_constrained_layout(False)``.
476
+ # This is potentially useful for animations where the tick labels may
477
+ # change length.
478
+ #
479
+ # Note that ``constrained_layout`` is turned off for ``ZOOM`` and ``PAN``
480
+ # GUI events for the backends that use the toolbar. This prevents the
481
+ # axes from changing position during zooming and panning.
482
+ #
457
483
###############################################################################
458
484
# Limitations
459
485
# ========================
0 commit comments