1
1
"""
2
2
=====================================
3
- Arranging multiple * Axes* in a Figure
3
+ Arranging multiple Axes in a Figure
4
4
=====================================
5
5
6
- Often more than one * Axes* is wanted on a figure at a time, usually
6
+ Often more than one Axes is wanted on a figure at a time, usually
7
7
organized into a regular grid. Matplotlib has a variety of tools for
8
- working with grids of * Axes* that have evolved over the history of the library.
8
+ working with grids of Axes that have evolved over the history of the library.
9
9
Here we will discuss the tools we think users should use most often, the tools
10
- that underpin how * Axes* are organized, and mention some of the older tools.
10
+ that underpin how Axes are organized, and mention some of the older tools.
11
11
12
12
.. note::
13
13
14
- Matplotlib uses *Axes* to refer to an *Artist* that contains plotting
15
- *Artists* and the x- and y-*Axis*. Another term that is often used is
16
- "subplot", which refers to an *Axes* that is arranged in a grid.
17
- See `<figure_parts>`_ for more details of Matplotlib terminology .
14
+ Matplotlib uses *Axes* to refer to the drawing area that contains
15
+ data, x- and y-axis, ticks, labels, title, etc. See <figure_parts>_ for
16
+ more details. Another term that is often used is "subplot", which refers
17
+ to an Axes that is in a grid with other Axes objects .
18
18
19
19
Overview
20
20
========
21
21
22
- Create grid-shaped combinations of * Axes*
23
- -----------------------------------------
22
+ Create grid-shaped combinations of Axes
23
+ ---------------------------------------
24
24
25
25
`~matplotlib.pyplot.subplots`
26
- The primary function used to create figures and a grid of * Axes* . It
27
- creates and places all * Axes* on the figure at once, and returns an
28
- object array with handles for the * Axes* in the grid. See
26
+ The primary function used to create figures and a grid of Axes. It
27
+ creates and places all Axes on the figure at once, and returns an
28
+ object array with handles for the Axes in the grid. See
29
29
`.Figure.subplots`.
30
30
31
31
or
32
32
33
33
`~matplotlib.pyplot.subplot_mosaic`
34
- A simple way to create figures and a grid of * Axes* , with the added
35
- flexibility that * Axes* can also span rows or columns. The * Axes*
34
+ A simple way to create figures and a grid of Axes, with the added
35
+ flexibility that Axes can also span rows or columns. The Axes
36
36
are returned in a labelled dictionary instead of an array. See also
37
37
`.Figure.subplot_mosaic` and :doc:`/tutorials/provisional/mosaic`.
38
38
39
- Sometimes it is natural to have more than one distinct group of * Axes* grids,
39
+ Sometimes it is natural to have more than one distinct group of Axes grids,
40
40
in which case Matplotlib has the concept of `~.figure.SubFigure`:
41
41
42
42
`~matplotlib.figure.SubFigure`
57
57
`~matplotlib.gridspec.SubplotSpec`
58
58
Specifies the location of the subplot in the given `.GridSpec`.
59
59
60
- Adding single * Axes* at a time
61
- ------------------------------
60
+ Adding single Axes at a time
61
+ ----------------------------
62
62
63
- The above functions create all * Axes* in a single function call. It is also
64
- possible to add * Axes* one at a time, and this was originally how Matplotlib
63
+ The above functions create all Axes in a single function call. It is also
64
+ possible to add Axes one at a time, and this was originally how Matplotlib
65
65
used to work. Doing so is generally less elegant and flexible, though
66
- sometimes useful for interactive work or to place an * Axes* in a custom
66
+ sometimes useful for interactive work or to place an Axes in a custom
67
67
location:
68
68
69
69
`~matplotlib.pyplot.subplot` or `.Figure.add_subplot`
85
85
# Basic 2x2 grid
86
86
# --------------
87
87
#
88
- # We can create a basic 2-by-2 grid of * Axes* using
88
+ # We can create a basic 2-by-2 grid of Axes using
89
89
# :func:`~matplotlib.pyplot.subplots`. It returns a
90
90
# :class:`~matplotlib.figure.Figure` instance and an array of
91
- # :class:`~matplotlib.axes.Axes` objects. The * Axes* objects can
92
- # be used to access methods to place artists on the * Axes* ; here we
91
+ # :class:`~matplotlib.axes.Axes` objects. The Axes objects can
92
+ # be used to access methods to place artists on the Axes; here we
93
93
# use `~.Axes.annotate`, but other examples could be `~.Axes.plot`,
94
94
# `~.Axes.pcolormesh`, etc.
95
95
108
108
fig .suptitle ('plt.subplots()' )
109
109
110
110
##############################################################################
111
- # We will annotate a lot of * Axes* , so lets encapsulate the annotation, rather
111
+ # We will annotate a lot of Axes, so lets encapsulate the annotation, rather
112
112
# than having that large piece of annotation code every time we need it:
113
113
114
114
@@ -132,10 +132,10 @@ def annotate_axes(ax, text, fontsize=18):
132
132
fig .suptitle ('plt.subplot_mosaic()' )
133
133
134
134
############################################################################
135
- # * Axes* spanning rows or columns in a grid
136
- # -----------------------------------------
135
+ # Axes spanning rows or columns in a grid
136
+ # ---------------------------------------
137
137
#
138
- # Sometimes we want * Axes* to span rows or columns of the grid.
138
+ # Sometimes we want Axes to span rows or columns of the grid.
139
139
# There are actually multiple ways to accomplish this, but the most
140
140
# convenient is probably to use `~.pyplot.subplot_mosaic` by repeating one
141
141
# of the keys:
@@ -171,13 +171,13 @@ def annotate_axes(ax, text, fontsize=18):
171
171
fig .suptitle ('plt.subplot_mosaic()' )
172
172
173
173
############################################################################
174
- # Nested * Axes* layouts
175
- # ---------------------
174
+ # Nested Axes layouts
175
+ # -------------------
176
176
#
177
- # Sometimes it is helpful to have two or more grids of * Axes* that
177
+ # Sometimes it is helpful to have two or more grids of Axes that
178
178
# may not need to be related to one another. The most simple way to
179
179
# accomplish this is to use `.Figure.subfigures`. Note that the alignement
180
- # of the subfigure layouts is independent with the * Axes* spines in each
180
+ # of the subfigure layouts is independent with the Axes spines in each
181
181
# subfigure having independent positions. See below for a more verbose
182
182
# way to acheive the same effect with `~.gridspec.GridSpecFromSubplotSpec`.
183
183
@@ -193,7 +193,7 @@ def annotate_axes(ax, text, fontsize=18):
193
193
subfigs [1 ].supylabel ('ylabel for subfigs[1]' )
194
194
195
195
############################################################################
196
- # It is also possible to nest * Axes* using `~.pyplot.subplot_mosaic` using
196
+ # It is also possible to nest Axes using `~.pyplot.subplot_mosaic` using
197
197
# nested lists. This method does not use subfigures, like above, so lacks
198
198
# the ability to add per-subfigure ``suptitle`` and ``supxlabel``, etc.
199
199
# Rather it is a conveneince wrapper around the `~.SubplotSpec.subgridspec`
@@ -212,13 +212,13 @@ def annotate_axes(ax, text, fontsize=18):
212
212
# Low-level and advanced grid methods
213
213
# ===================================
214
214
#
215
- # Internally, the arrangement of a grid of * Axes* is controlled by creating
215
+ # Internally, the arrangement of a grid of Axes is controlled by creating
216
216
# instances of `~.GridSpec` and `~.SubplotSpec`. *GridSpec* defines a
217
217
# (possibly non-uniform) grid of cells. Indexing into the *GridSpec* returns
218
218
# a SubplotSpec that covers one or more grid cells, and can be used to
219
- # specify the location of an * Axes* .
219
+ # specify the location of an Axes.
220
220
#
221
- # The following examples show how to use low-level methods to arrange * Axes*
221
+ # The following examples show how to use low-level methods to arrange Axes
222
222
# using *GridSpec* objects.
223
223
#
224
224
# Basic 2x2 grid
@@ -240,12 +240,12 @@ def annotate_axes(ax, text, fontsize=18):
240
240
fig .suptitle ('Manually added subplots using add_gridspec' )
241
241
242
242
##############################################################################
243
- # * Axes* spanning rows or grids in a grid
244
- # ---------------------------------------
243
+ # Axes spanning rows or grids in a grid
244
+ # -------------------------------------
245
245
#
246
246
# We can index the *spec* array using `NumPy slice syntax
247
247
# <https://numpy.org/doc/stable/reference/arrays.indexing.html>`_
248
- # and the new * Axes* will span the slice. This would be the same
248
+ # and the new Axes will span the slice. This would be the same
249
249
# as ``fig, axd = plt.subplot_mosaic([['ax0', 'ax0'], ['ax1', 'ax2']], ...)``:
250
250
251
251
fig = plt .figure (figsize = (4.5 , 3.5 ), constrained_layout = True )
@@ -267,7 +267,7 @@ def annotate_axes(ax, text, fontsize=18):
267
267
# option is not compatible with ``constrained_layout`` or
268
268
# `.Figure.tight_layout` which both ignore *left* and *right* and adjust
269
269
# subplot sizes to fill the figure. Usually such manual placement
270
- # requires iterations to make the * Axes* tick labels not overlap the * Axes* .
270
+ # requires iterations to make the Axes tick labels not overlap the Axes.
271
271
#
272
272
# These spacing parameters can also be passed to `~.pyplot.subplots` and
273
273
# `~.pyplot.subplot_mosaic` as the *gridspec_kw* argument.
@@ -288,7 +288,7 @@ def annotate_axes(ax, text, fontsize=18):
288
288
# -------------------------------
289
289
#
290
290
# You can create nested layout similar to `~.Figure.subfigures` using
291
- # `~.gridspec.SubplotSpec.subgridspec`. Here the * Axes* spines _are_
291
+ # `~.gridspec.SubplotSpec.subgridspec`. Here the Axes spines _are_
292
292
# aligned.
293
293
#
294
294
# Note this is also available from the more verbose
@@ -316,7 +316,7 @@ def annotate_axes(ax, text, fontsize=18):
316
316
317
317
###############################################################################
318
318
# Here's a more sophisticated example of nested *GridSpec*: We create an outer
319
- # 4x4 grid with each cell containing and inner 3x3 grid of * Axes* . We outline
319
+ # 4x4 grid with each cell containing and inner 3x3 grid of Axes. We outline
320
320
# the outer 4x4 grid by hiding appropriate spines in each of the inner 3x3
321
321
# grids.
322
322
0 commit comments