|
53 | 53 | # |
54 | 54 | # This algorithm also has the following notable properties: |
55 | 55 | # |
56 | | -# * For very simple subplot grids (e.g. ``plot.subplots(ncols=2, nrows=3)``), |
57 | | -# `aspect`, `axwidth`, and `axheight` apply to every subplot in the figure -- |
58 | | -# not just the reference subplot. |
| 56 | +# * For very simple subplot grids (i.e. subplots created with the `ncols` and |
| 57 | +# `nrows` arguments), the arguments `aspect`, `axwidth`, and `axheight` apply |
| 58 | +# to every subplot in the figure -- not just the reference subplot. |
59 | 59 | # * When the reference subplot `aspect ratio\ |
60 | 60 | # <https://matplotlib.org/2.0.2/examples/pylab_examples/equal_aspect_ratio.html>`__ |
61 | 61 | # has been manually overridden (e.g. with ``ax.set_aspect(1)``) or is set |
|
144 | 144 | # Automatic subplot spacing |
145 | 145 | # ------------------------- |
146 | 146 | # |
147 | | -# By default, ProPlot applies a *tight layout* algorithm to every figure. |
148 | | -# This algorithm automatically adjusts the space between subplot rows and |
149 | | -# columns and the figure edge to accomadate labels. It can be disabled by |
150 | | -# passing ``tight=False`` to `~proplot.ui.subplots`. |
151 | | -# |
| 147 | +# In addition to automatic figure sizing, by default ProPlot applies a *tight layout* |
| 148 | +# algorithm to every figure. This algorithm automatically adjusts the space between |
| 149 | +# subplot rows and columns and the figure edge to accommodate labels. |
| 150 | +# It can be disabled by passing ``tight=False`` to `~proplot.ui.subplots`. |
152 | 151 | # While matplotlib has `its own tight layout algorithm |
153 | 152 | # <https://matplotlib.org/3.1.1/tutorials/intermediate/tight_layout_guide.html>`__, |
154 | | -# ProPlot's algorithm permits variable spacing between subsequent subplot |
155 | | -# rows and columns (see the new `~proplot.gridspec.GridSpec` class) and may |
156 | | -# change the figure size (depending on the keyword arguments passed to |
157 | | -# `~proplot.ui.subplots`). |
| 153 | +# ProPlot's algorithm may change the figure size to accommodate the correct spacing |
| 154 | +# and permits variable spacing between subsequent subplot rows and columns (see the |
| 155 | +# new `~proplot.gridspec.GridSpec` class for details). |
158 | 156 | # |
159 | | -# ProPlot's tight layout algorithm can also be easily overridden. When you |
| 157 | +# The tight layout algorithm can also be easily overridden. When you |
160 | 158 | # pass a spacing argument like `left`, `right`, `top`, `bottom`, `wspace`, or |
161 | | -# `hspace` to `~proplot.ui.subplots`, that value is always respected: |
| 159 | +# `hspace` to `~proplot.ui.subplots`, that value is always respected. For example: |
162 | 160 | # |
163 | | -# * With ``left='2em'``, the left margin is fixed but the right, bottom, and |
164 | | -# top margins are calculated automatically. |
165 | | -# * With ``wspace=('3em', None)`` (and ``ncols=3``), the space between the |
166 | | -# first two columns is fixed, while the space between the second two columns |
167 | | -# is calculated automatically. |
| 161 | +# * ``left='2em'`` fixes the left margin, while the right, bottom, and |
| 162 | +# top margins are determined automatically. |
| 163 | +# * ``wspace='1em'`` fixes the spaces between subplot columns, while the spaces |
| 164 | +# between subplot rows are determined automatically. |
| 165 | +# * ``wspace=('3em', None)`` fixes the space between the first two columns of |
| 166 | +# a three-column plot, while the space between the second two columns is |
| 167 | +# determined automatically. |
168 | 168 | # |
169 | 169 | # The below examples demonstrate how the tight layout algorithm permits |
170 | 170 | # variable spacing between subplot rows and columns. |
|
201 | 201 |
|
202 | 202 | # Formatting that stress-tests the algorithm |
203 | 203 | axs.format( |
204 | | - xlim=(-1.2, 1.2), ylim=(-1.2, 1.2), xlocator=1, ylocator=1, |
| 204 | + xlim=(-1.5, 1.5), ylim=(-1.5, 1.5), xlocator=1, ylocator=1, |
205 | 205 | suptitle='Tight layout with user overrides', |
206 | 206 | rowlabels=['Row 1', 'Row 2', 'Row 3'], |
207 | 207 | collabels=['Column 1', 'Column 2', 'Column 3', 'Column 4'] |
|
245 | 245 | wspace=('10pt', '20pt'), right='10mm' |
246 | 246 | ) |
247 | 247 | panel = axs[2].panel_axes('r', width='2em') |
| 248 | + panel.format(xlim=(0, 1)) |
248 | 249 | axs.format( |
249 | 250 | suptitle='Arguments with arbitrary units', |
250 | | - xlabel='x axis', ylabel='y axis' |
| 251 | + xlabel='x axis', ylabel='y axis', |
| 252 | + xlim=(0, 1), ylim=(0, 1), |
251 | 253 | ) |
252 | 254 |
|
253 | 255 |
|
254 | 256 | # %% [raw] raw_mimetype="text/restructuredtext" |
255 | 257 | # .. _ug_abc: |
256 | 258 | # |
257 | | -# Subplot a-b-c labels |
| 259 | +# A-b-c subplot labels |
258 | 260 | # -------------------- |
259 | 261 | # |
260 | 262 | # ProPlot can be used to add "a-b-c" labels to subplots. This is possible |
261 | | -# because `~proplot.ui.subplots` assigns unique |
262 | | -# `~proplot.axes.Axes.number`\ s to each subplot. If you passed an `array` to |
| 263 | +# because `~proplot.ui.subplots` assigns unique `~proplot.axes.Axes.number`\ s |
| 264 | +# to each subplot. If you :ref:`passed an array <ug_intro>` to |
263 | 265 | # `~proplot.ui.subplots`, the subplot numbers correspond to the numbers in |
264 | | -# the array. Otherwise, if you used the `ncols` and `nrows` keyword |
265 | | -# arguments, the number order is row-major by default but can be switched to |
266 | | -# column-major by passing ``order='C'`` to `~proplot.ui.subplots`. The number |
267 | | -# order also determines the subplot order in the |
268 | | -# `~proplot.ui.SubplotsContainer` returned by `~proplot.ui.subplots`. |
| 266 | +# the array. If you used the `ncols` and `nrows` keyword arguments, the number |
| 267 | +# order is row-major by default but can be switched to column-major by passing |
| 268 | +# ``order='C'`` to `~proplot.ui.subplots`. The number order also determines the |
| 269 | +# subplot order in the `~proplot.ui.SubplotsContainer` returned by |
| 270 | +# `~proplot.ui.subplots`. |
269 | 271 | # |
270 | 272 | # To turn on "a-b-c" labels, set :rcraw:`abc` to ``True`` or pass |
271 | 273 | # ``abc=True`` to `~proplot.axes.Axes.format` (see |
|
287 | 289 | # %% [raw] raw_mimetype="text/restructuredtext" |
288 | 290 | # .. _ug_share: |
289 | 291 | # |
290 | | -# Shared and spanning labels |
291 | | -# -------------------------- |
292 | | -# |
293 | | -# Matplotlib has an "axis sharing" feature that holds axis limits the same |
294 | | -# for axes within a grid of subplots. But this has no effect on the axis |
295 | | -# labels and tick labels, which can lead to lots of redundancies. |
| 292 | +# Axis sharing |
| 293 | +# ------------ |
296 | 294 | # |
297 | | -# To help you eliminate these redundancies, ProPlot introduces four |
298 | | -# axis-sharing options and a new spanning label option, controlled by the |
299 | | -# `share`, `sharex`, `sharey`, `span`, `spanx`, and `spany` |
300 | | -# `~proplot.ui.subplots` keyword args. |
| 295 | +# Redundant labels are a common problem for figures with lots of subplots. To |
| 296 | +# address this, `matplotlib.pyplot.subplots` includes `sharex` and `sharey` |
| 297 | +# keywords that permit sharing axis limits, ticks, and tick labels between like |
| 298 | +# rows and columns of subplots. However there is no convenient way to enable |
| 299 | +# axis sharing between complex grids of subplots, nor is there a way to share axis |
| 300 | +# labels between subplots in the same row or column. |
301 | 301 | # |
302 | | -# #. Level ``1`` hides inner *x* and *y* axis labels. |
303 | | -# #. Level ``2`` is the same as ``1``, but the *x* and *y* axis limits are locked. |
304 | | -# #. Level ``3`` is the same as ``2``, but the *x* and *y* tick labels are hidden. |
| 302 | +# ProPlot expands upon this feature by introducing a new option for drawing |
| 303 | +# labels that "span" subplots in the same row or column, controlled by the |
| 304 | +# `spanx` and `spany` keywords, along with four axis-sharing "levels" |
| 305 | +# rather than just one, controlled with the `sharex` and `sharey` keywords: |
305 | 306 | # |
306 | | -# "Spanning labels" are centered *x* and *y* axis labels used for subplots |
307 | | -# whose spines are on the same row or column. See the below example. |
| 307 | +# * Level ``0`` disables axis sharing. |
| 308 | +# * Level ``1`` shares duplicate *x* and *y* axis labels, but nothing else. |
| 309 | +# * Level ``2`` is the same as ``1``, but the *x* and *y* axis limits, ticks, |
| 310 | +# and scales are also shared. |
| 311 | +# * Level ``3`` is the same as ``2``, but the *x* and *y* tick labels are |
| 312 | +# also shared. |
308 | 313 | # |
309 | | -# Note that the the "shared" and "spanning" axes are determined automatically |
310 | | -# based on the extent of each subplot in the `~proplot.gridspec.GridSpec`. |
311 | | -# Since ProPlot uses just one `~proplot.gridspec.GridSpec` per figure, this |
312 | | -# can be done with zero ambiguity. |
| 314 | +# These features are best illustrated by example (see below). Note that since |
| 315 | +# "shared" and "spanning" labels are determined automatically based on position of |
| 316 | +# each subplot in the `~proplot.gridspec.GridSpec`, these features work for |
| 317 | +# arbitrarily complex figures. Since ProPlot uses just one `~proplot.gridspec.GridSpec` |
| 318 | +# per figure, this can be done with zero ambiguity. |
313 | 319 |
|
314 | 320 | # %% |
315 | 321 | import proplot as plot |
|
326 | 332 | # Same plot with different sharing and spanning settings |
327 | 333 | for share in (0, 1, 2, 3): |
328 | 334 | fig, axs = plot.subplots( |
329 | | - ncols=4, aspect=1, axwidth=1.2, |
| 335 | + ncols=4, aspect=1, axwidth=1.06, |
330 | 336 | sharey=share, spanx=share // 2 |
331 | 337 | ) |
332 | 338 | for ax, data in zip(axs, datas): |
333 | 339 | on = ['off', 'on'][share // 2] |
334 | 340 | ax.plot(data, cycle=colors) |
335 | 341 | ax.format( |
336 | | - suptitle=f'Axis-sharing level: {share}, spanning labels {on}', |
| 342 | + suptitle=f'Sharing level {share}, spanning labels {on}', |
337 | 343 | grid=False, xlabel='spanning', ylabel='shared' |
338 | 344 | ) |
339 | 345 |
|
|
0 commit comments