@@ -105,7 +105,7 @@ def example_plot(ax, fontsize=12, nodec=False):
105
105
fig .colorbar (im , ax = ax , shrink = 0.6 )
106
106
107
107
############################################################################
108
- # If you specify multiple axes to the ``ax`` argument of ``colorbar``,
108
+ # If you specify a list of axes to the ``ax`` argument of ``colorbar``,
109
109
# constrained_layout will take space from all axes that share the same
110
110
# gridspec.
111
111
@@ -114,6 +114,31 @@ def example_plot(ax, fontsize=12, nodec=False):
114
114
im = ax .pcolormesh (arr , rasterized = True )
115
115
fig .colorbar (im , ax = axs , shrink = 0.6 )
116
116
117
+ ############################################################################
118
+ # Note that there is a bit of a subtlety when specifying a single axes
119
+ # as the parent. In the following, it might be desirable and expected
120
+ # for the colorbars to line up, but they don't because the colorbar paired
121
+ # with the bottom axes is tied to the subplotspec of the axes, and hence
122
+ # shrinks when the gridspec-level colorbar is added.
123
+
124
+ fig , axs = plt .subplots (3 , 1 , figsize = (4 , 4 ), constrained_layout = True )
125
+ for ax in axs [:2 ]:
126
+ im = ax .pcolormesh (arr , rasterized = True )
127
+ fig .colorbar (im , ax = axs [:2 ], shrink = 0.6 )
128
+ im = axs [2 ].pcolormesh (arr , rasterized = True )
129
+ fig .colorbar (im , ax = axs [2 ], shrink = 0.6 )
130
+
131
+ ############################################################################
132
+ # The API to make a single-axes behave like a list of axes is to specify
133
+ # it as a list, as below:
134
+
135
+ fig , axs = plt .subplots (3 , 1 , figsize = (4 , 4 ), constrained_layout = True )
136
+ for ax in axs [:2 ]:
137
+ im = ax .pcolormesh (arr , rasterized = True )
138
+ fig .colorbar (im , ax = axs [:2 ], shrink = 0.6 )
139
+ im = axs [2 ].pcolormesh (arr , rasterized = True )
140
+ fig .colorbar (im , ax = [axs [2 ]], shrink = 0.6 )
141
+
117
142
####################################################
118
143
# Suptitle
119
144
# =========
0 commit comments