11"""
2- ===================================
3- Arranging multiple Axes in a Figure
4- ===================================
2+ =====================================
3+ Arranging multiple * Axes* in a Figure
4+ =====================================
55
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
77organized 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.
99Here 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.
1111
1212.. note::
1313
14- We use "Axes" to refer to the object that contains plotting
15- artists and the x- and y-Axis. See `<figure_parts>`_ for more details of
16- Matplotlib terminology.
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.
1718
1819Overview
1920========
2021
21- Create grid-shaped combinations of Axes
22- ---------------------------------------
22+ Create grid-shaped combinations of * Axes*
23+ -----------------------------------------
2324
2425`~matplotlib.pyplot.subplots`
25- The primary function used to create figures and a grid of Axes. It
26- creates and places all Axes on the figure at once, and returns an
27- 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
2829 `.Figure.subplots`.
2930
3031or
3132
3233`~matplotlib.pyplot.subplot_mosaic`
33- A simple way to create figures and a grid of Axes, with the added
34- 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*
3536 are returned in a labelled dictionary instead of an array. See also
3637 `.Figure.subplot_mosaic` and :doc:`/tutorials/provisional/mosaic`.
3738
38- 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,
3940in which case Matplotlib has the concept of `~.figure.SubFigure`:
4041
4142`~matplotlib.figure.SubFigure`
5657`~matplotlib.gridspec.SubplotSpec`
5758 Specifies the location of the subplot in the given `.GridSpec`.
5859
59- Adding single Axes at a time
60- ----------------------------
60+ Adding single * Axes* at a time
61+ ------------------------------
6162
62- The above functions create all Axes in a single function call. It is also
63- 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
6465used to work. Doing so is generally less elegant and flexible, though
65- sometimes useful for interactive work or to place an Axes in a custom location:
66+ sometimes useful for interactive work or to place an * Axes* in a custom location:
6667
6768`~matplotlib.pyplot.subplot` or `.Figure.add_subplot`
6869 Adds a single subplot on a figure, with 1-based indexing (inherited from
8384# Basic 2x2 grid
8485# --------------
8586#
86- # We can create a basic 2-by-2 grid of Axes using
87+ # We can create a basic 2-by-2 grid of * Axes* using
8788# :func:`~matplotlib.pyplot.subplots`. It returns a
8889# :class:`~matplotlib.figure.Figure` instance and an array of
89- # :class:`~matplotlib.axes.Axes` objects. The Axes objects can
90- # be used to access methods to place artists on the Axes; here we
90+ # :class:`~matplotlib.axes.Axes` objects. The * Axes* objects can
91+ # be used to access methods to place artists on the * Axes* ; here we
9192# use `~.Axes.annotate`, but other examples could be `~.Axes.plot`,
9293# `~.Axes.pcolormesh`, etc.
9394
106107fig .suptitle ('plt.subplots()' )
107108
108109##############################################################################
109- # We will annotate a lot of Axes, so lets encapsulate the annotation, rather
110+ # We will annotate a lot of * Axes* , so lets encapsulate the annotation, rather
110111# than having that large piece of annotation code every time we need it:
111112
112113
@@ -130,10 +131,10 @@ def annotate_axes(ax, text, fontsize=18):
130131fig .suptitle ('plt.subplot_mosaic()' )
131132
132133############################################################################
133- # Axes spanning rows or columns in a grid
134- # ---------------------------------------
134+ # * Axes* spanning rows or columns in a grid
135+ # -----------------------------------------
135136#
136- # Sometimes we want Axes to span rows or columns of the grid.
137+ # Sometimes we want * Axes* to span rows or columns of the grid.
137138# There are actually multiple ways to accomplish this, but the most
138139# convenient is probably to use `~.pyplot.subplot_mosaic` by repeating one
139140# of the keys:
@@ -169,13 +170,13 @@ def annotate_axes(ax, text, fontsize=18):
169170fig .suptitle ('plt.subplot_mosaic()' )
170171
171172############################################################################
172- # Nested Axes layouts
173- # -------------------
173+ # Nested * Axes* layouts
174+ # ---------------------
174175#
175- # Sometimes it is helpful to have two or more grids of Axes that
176+ # Sometimes it is helpful to have two or more grids of * Axes* that
176177# may not need to be related to one another. The most simple way to
177178# accomplish this is to use `.Figure.subfigures`. Note that the alignement
178- # of the subfigure layouts is independent with the Axes spines in each
179+ # of the subfigure layouts is independent with the * Axes* spines in each
179180# subfigure having independent positions. See below for a more verbose
180181# way to acheive the same effect with `~.gridspec.GridSpecFromSubplotSpec`.
181182
@@ -191,7 +192,7 @@ def annotate_axes(ax, text, fontsize=18):
191192subfigs [1 ].supylabel ('ylabel for subfigs[1]' )
192193
193194############################################################################
194- # It is also possible to nest Axes using `~.pyplot.subplot_mosaic` using
195+ # It is also possible to nest * Axes* using `~.pyplot.subplot_mosaic` using
195196# nested lists. This method does not use subfigures, like above, so lacks
196197# the ability to add per-subfigure ``suptitle`` and ``supxlabel``, etc.
197198# Rather it is a conveneince wrapper around the `~.SubplotSpec.subgridspec`
@@ -210,14 +211,14 @@ def annotate_axes(ax, text, fontsize=18):
210211# Low-level and advanced grid methods
211212# ===================================
212213#
213- # Internally, the arrangement of a grid of Axes is controlled by creating
214- # instances of `~.GridSpec` and `~.SubplotSpec`. GridSpec defines a
215- # (possibly non-uniform) grid of cells. Indexing into the GridSpec returns
214+ # Internally, the arrangement of a grid of * Axes* is controlled by creating
215+ # instances of `~.GridSpec` and `~.SubplotSpec`. * GridSpec* defines a
216+ # (possibly non-uniform) grid of cells. Indexing into the * GridSpec* returns
216217# a SubplotSpec that covers one or more grid cells, and can be used to
217- # specify the location of an Axes or "subplot" .
218+ # specify the location of an * Axes* .
218219#
219- # The following examples show how to use low-level methods to arrange Axes
220- # using GridSpec objects.
220+ # The following examples show how to use low-level methods to arrange * Axes*
221+ # using * GridSpec* objects.
221222#
222223# Basic 2x2 grid
223224# --------------
@@ -238,12 +239,12 @@ def annotate_axes(ax, text, fontsize=18):
238239fig .suptitle ('Manually added subplots using add_gridspec' )
239240
240241##############################################################################
241- # Axes spanning rows or grids in a grid
242- # -------------------------------------
242+ # * Axes* spanning rows or grids in a grid
243+ # ---------------------------------------
243244#
244245# We can index the *spec* array using `NumPy slice syntax
245246# <https://numpy.org/doc/stable/reference/arrays.indexing.html>`_
246- # and the new Axes will span the slice. This would be the same
247+ # and the new * Axes* will span the slice. This would be the same
247248# as ``fig, axd = plt.subplot_mosaic([['ax0', 'ax0'], ['ax1', 'ax2']], ...)``:
248249
249250fig = plt .figure (figsize = (4.5 , 3.5 ), constrained_layout = True )
@@ -257,15 +258,15 @@ def annotate_axes(ax, text, fontsize=18):
257258fig .suptitle ('Manually added subplots, spanning a column' )
258259
259260###############################################################################
260- # Manual adjustments to a GridSpec layout
261- # ---------------------------------------
261+ # Manual adjustments to a * GridSpec* layout
262+ # -----------------------------------------
262263#
263- # When a GridSpec is explicitly used, you can adjust the layout
264- # parameters of subplots that are created from the GridSpec. Note this
264+ # When a * GridSpec* is explicitly used, you can adjust the layout
265+ # parameters of subplots that are created from the * GridSpec* . Note this
265266# option is not compatible with ``constrained_layout`` or
266267# `.Figure.tight_layout` which both ignore *left* and *right* and adjust
267268# subplot sizes to fill the figure. Usually such manual placement
268- # requires iterations to make the Axes tick labels not overlap the Axes.
269+ # requires iterations to make the * Axes* tick labels not overlap the * Axes* .
269270#
270271# These spacing parameters can also be passed to `~.pyplot.subplots` and
271272# `~.pyplot.subplot_mosaic` as the *gridspec_kw* argument.
@@ -286,7 +287,7 @@ def annotate_axes(ax, text, fontsize=18):
286287# -------------------------------
287288#
288289# You can create nested layout similar to `~.Figure.subfigures` using
289- # `~.gridspec.SubplotSpec.subgridspec`. Here the Axes spines _are_
290+ # `~.gridspec.SubplotSpec.subgridspec`. Here the * Axes* spines _are_
290291# aligned.
291292#
292293# Note this is also available from the more verbose
@@ -313,9 +314,10 @@ def annotate_axes(ax, text, fontsize=18):
313314fig .suptitle ('nested gridspecs' )
314315
315316###############################################################################
316- # Here's a more sophisticated example of nested GridSpec: We create an outer
317- # 4x4 grid with each cell containing and inner 3x3 grid of Axes. We outline the
318- # outer 4x4 grid by hiding appropriate spines in each of the inner 3x3 grids.
317+ # Here's a more sophisticated example of nested *GridSpec*: We create an outer
318+ # 4x4 grid with each cell containing and inner 3x3 grid of *Axes*. We outline
319+ # the outer 4x4 grid by hiding appropriate spines in each of the inner 3x3
320+ # grids.
319321
320322
321323def squiggle_xy (a , b , c , d , i = np .arange (0.0 , 2 * np .pi , 0.05 )):
0 commit comments