|
20 | 20 | # |
21 | 21 | # This section documents a variety of features related to proplot subplots, |
22 | 22 | # including a-b-c subplot labels, axis sharing between subplots, automatic |
23 | | -# "tight layout" spacing between subplots, and a unique feature where the |
24 | | -# figure dimensions are automatically adjusted based on the subplot geometry. |
| 23 | +# "tight layout" spacing between subplots, and a unique feature where the figure |
| 24 | +# width and/or height are automatically adjusted based on the subplot geometry. |
25 | 25 | # |
26 | 26 | # .. note:: |
27 | 27 | # |
|
30 | 30 | # does not officially support the "nested" matplotlib structures |
31 | 31 | # `~matplotlib.gridspec.GridSpecFromSubplotSpec` and `~matplotlib.figure.SubFigure`. |
32 | 32 | # These restrictions have the advantage of 1) considerably simplifying the |
33 | | -# :ref:`tight layout <ug_tight>` and :ref:`figure dimensions <ug_autosize>` |
| 33 | +# :ref:`tight layout <ug_tight>` and :ref:`figure size <ug_autosize>` |
34 | 34 | # algorithms and 2) reducing the ambiguity of :ref:`a-b-c label assignment <ug_abc>` |
35 | 35 | # and :ref:`automatic axis sharing <ug_share>` between subplots. If you need the |
36 | 36 | # features associated with "nested" matplotlib structures, some are reproducible |
|
105 | 105 | # %% [raw] raw_mimetype="text/restructuredtext" |
106 | 106 | # .. _ug_autosize: |
107 | 107 | # |
108 | | -# Figure dimensions |
109 | | -# ----------------- |
| 108 | +# Figure width and height |
| 109 | +# ----------------------- |
110 | 110 | # |
111 | 111 | # Proplot automatically adjusts the figure width and height by default to |
112 | 112 | # respect the physical size of the "reference" subplot and the geometry of the |
|
152 | 152 | # `~matplotlib.axes.Axes.set_aspect` or filling the subplot with a |
153 | 153 | # :ref:`geographic projection <ug_geo>`, `~proplot.axes.PlotAxes.imshow` |
154 | 154 | # plot, or `~proplot.axes.PlotAxes.heatmap` plot), then this is used as |
155 | | -# the default value for the refernece aspect ratio `refaspect`. This helps |
| 155 | +# the default value for the reference aspect ratio `refaspect`. This helps |
156 | 156 | # minimize excess space between grids of subplots with fixed aspect ratios. |
157 | 157 | # * For the simplest subplot grids (e.g., those created by passing integers to |
158 | 158 | # `~proplot.figure.Figure.add_subplot` or passing `ncols` or `nrows` to |
|
213 | 213 | # %% [raw] raw_mimetype="text/restructuredtext" |
214 | 214 | # .. _ug_tight: |
215 | 215 | # |
216 | | -# Subplot spacing |
217 | | -# --------------- |
| 216 | +# Spaces and tight layout |
| 217 | +# ----------------------- |
218 | 218 | # |
219 | 219 | # Proplot automatically adjusts the spacing between subplots |
220 | 220 | # by default to accomadate labels using its own `"tight layout" algorithm |
|
264 | 264 | # %% |
265 | 265 | import proplot as pplt |
266 | 266 |
|
267 | | -# Stress test of the tight layout algorithm |
268 | | -# Add large labels along the edge of one subplot |
269 | | -equals = [('unequal', False), ('equal', True)] |
270 | | -groups = [('grouped', True), ('ungrouped', False)] |
271 | | -for i in range(2): |
272 | | - name1, equal = equals[i] |
273 | | - name2, group = groups[i] |
274 | | - suffix = ' (default)' if i == 0 else '' |
275 | | - suptitle = f'Tight layout with "{name1}" and "{name2}" row-column spacing{suffix}' |
276 | | - fig, axs = pplt.subplots( |
277 | | - nrows=3, ncols=3, refwidth=1.1, share=False, equal=equal, group=group, |
278 | | - ) |
279 | | - axs[1].format( |
280 | | - xlabel='xlabel\nxlabel', |
281 | | - ylabel='ylabel\nylabel\nylabel\nylabel' |
282 | | - ) |
283 | | - axs[3:6:2].format( |
284 | | - title='Title\nTitle', |
285 | | - titlesize='med', |
286 | | - ) |
287 | | - axs.format( |
288 | | - grid=False, |
289 | | - toplabels=('Column 1', 'Column 2', 'Column 3'), |
290 | | - leftlabels=('Row 1', 'Row 2', 'Row 3'), |
291 | | - suptitle=suptitle, |
292 | | - ) |
293 | | - |
294 | | -# %% |
295 | | -import proplot as pplt |
296 | | - |
297 | 267 | # Stress test of the tight layout algorithm |
298 | 268 | # This time override the algorithm between selected subplot rows/columns |
299 | 269 | fig, axs = pplt.subplots( |
|
318 | 288 | axs[:, 0].format(ylabel='ylabel') |
319 | 289 |
|
320 | 290 |
|
| 291 | +# %% |
| 292 | +import proplot as pplt |
| 293 | + |
| 294 | +# Stress test of the tight layout algorithm |
| 295 | +# Add large labels along the edge of one subplot |
| 296 | +equals = [('unequal', False), ('unequal', False), ('equal', True)] |
| 297 | +groups = [('grouped', True), ('ungrouped', False), ('grouped', True)] |
| 298 | +for (name1, equal), (name2, group) in zip(equals, groups): |
| 299 | + suffix = ' (default)' if group and not equal else '' |
| 300 | + suptitle = f'Tight layout with "{name1}" and "{name2}" row-column spacing{suffix}' |
| 301 | + fig, axs = pplt.subplots( |
| 302 | + nrows=3, ncols=3, refwidth=1.1, share=False, equal=equal, group=group, |
| 303 | + ) |
| 304 | + axs[1].format( |
| 305 | + xlabel='xlabel\nxlabel', |
| 306 | + ylabel='ylabel\nylabel\nylabel\nylabel' |
| 307 | + ) |
| 308 | + axs[3:6:2].format( |
| 309 | + title='Title\nTitle', |
| 310 | + titlesize='med', |
| 311 | + ) |
| 312 | + axs.format( |
| 313 | + grid=False, |
| 314 | + toplabels=('Column 1', 'Column 2', 'Column 3'), |
| 315 | + leftlabels=('Row 1', 'Row 2', 'Row 3'), |
| 316 | + suptitle=suptitle, |
| 317 | + ) |
| 318 | + |
321 | 319 | # %% [raw] raw_mimetype="text/restructuredtext" tags=[] |
322 | 320 | # .. _ug_share: |
323 | 321 | # |
|
0 commit comments