Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2afd187

Browse files
committed
DOC
1 parent 118aa9f commit 2afd187

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tutorials/intermediate/arranging_axes.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,36 @@ def annotate_axes(ax, text, fontsize=18):
134134
annotate_axes(axd[k], f'axd["{k}"]', fontsize=14)
135135
fig.suptitle('plt.subplot_mosaic()')
136136

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+
137167
############################################################################
138168
# Axes spanning rows or columns in a grid
139169
# ---------------------------------------

0 commit comments

Comments
 (0)