@@ -134,6 +134,36 @@ def annotate_axes(ax, text, fontsize=18):
134
134
annotate_axes (axd [k ], f'axd["{ k } "]' , fontsize = 14 )
135
135
fig .suptitle ('plt.subplot_mosaic()' )
136
136
137
+ #############################################################################
138
+ #
139
+ # Grids of fixed-aspect ratio Axes
140
+ # --------------------------------
141
+ #
142
+ # Fixed-aspect ratio axes are common for images or maps. However, they
143
+ # present a challenge to layout because two sets of constraints are being
144
+ # imposed on the size of the Axes - that they fit in the figure and that they
145
+ # have a set aspect ratio. This leads to large gaps between Axes by default:
146
+ #
147
+
148
+ fig , axs = plt .subplots (2 , 2 , layout = "constrained" , figsize = (5.5 , 3.5 ))
149
+ for ax in axs .flat :
150
+ ax .set_aspect (1 )
151
+ fig .suptitle ('Fixed aspect Axes' )
152
+
153
+ ############################################################################
154
+ # One way to address this is to change the aspect of the figure to be close
155
+ # to the aspect ratio of the Axes, however that requires trial and error.
156
+ # Matplotlib also supplies ``layout="compressed"``, which will work with
157
+ # simple grids to reduce the gaps between Axes. (The ``mpl_toolkits`` also
158
+ # provides `~.mpl_toolkits.axes_grid1.axes_grid.ImageGrid` to accomplish
159
+ # a similar effect, but with a non-standard Axes class).
160
+
161
+ fig , axs = plt .subplots (2 , 2 , layout = "compressed" , figsize = (5.5 , 3.5 ))
162
+ for ax in axs .flat :
163
+ ax .set_aspect (1 )
164
+ fig .suptitle ('Fixed aspect Axes: compressed' )
165
+
166
+
137
167
############################################################################
138
168
# Axes spanning rows or columns in a grid
139
169
# ---------------------------------------
0 commit comments