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
67+ location:
6668
6769`~matplotlib.pyplot.subplot` or `.Figure.add_subplot`
6870 Adds a single subplot on a figure, with 1-based indexing (inherited from
8385# Basic 2x2 grid
8486# --------------
8587#
86- # 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
8789# :func:`~matplotlib.pyplot.subplots`. It returns a
8890# :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
91+ # :class:`~matplotlib.axes.Axes` objects. The * Axes* objects can
92+ # be used to access methods to place artists on the * Axes* ; here we
9193# use `~.Axes.annotate`, but other examples could be `~.Axes.plot`,
9294# `~.Axes.pcolormesh`, etc.
9395
106108fig .suptitle ('plt.subplots()' )
107109
108110##############################################################################
109- # 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
110112# than having that large piece of annotation code every time we need it:
111113
112114
@@ -130,10 +132,10 @@ def annotate_axes(ax, text, fontsize=18):
130132fig .suptitle ('plt.subplot_mosaic()' )
131133
132134############################################################################
133- # Axes spanning rows or columns in a grid
134- # ---------------------------------------
135+ # * Axes* spanning rows or columns in a grid
136+ # -----------------------------------------
135137#
136- # 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.
137139# There are actually multiple ways to accomplish this, but the most
138140# convenient is probably to use `~.pyplot.subplot_mosaic` by repeating one
139141# of the keys:
@@ -169,13 +171,13 @@ def annotate_axes(ax, text, fontsize=18):
169171fig .suptitle ('plt.subplot_mosaic()' )
170172
171173############################################################################
172- # Nested Axes layouts
173- # -------------------
174+ # Nested * Axes* layouts
175+ # ---------------------
174176#
175- # 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
176178# may not need to be related to one another. The most simple way to
177179# accomplish this is to use `.Figure.subfigures`. Note that the alignement
178- # 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
179181# subfigure having independent positions. See below for a more verbose
180182# way to acheive the same effect with `~.gridspec.GridSpecFromSubplotSpec`.
181183
@@ -191,7 +193,7 @@ def annotate_axes(ax, text, fontsize=18):
191193subfigs [1 ].supylabel ('ylabel for subfigs[1]' )
192194
193195############################################################################
194- # 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
195197# nested lists. This method does not use subfigures, like above, so lacks
196198# the ability to add per-subfigure ``suptitle`` and ``supxlabel``, etc.
197199# Rather it is a conveneince wrapper around the `~.SubplotSpec.subgridspec`
@@ -210,14 +212,14 @@ def annotate_axes(ax, text, fontsize=18):
210212# Low-level and advanced grid methods
211213# ===================================
212214#
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
215+ # Internally, the arrangement of a grid of * Axes* is controlled by creating
216+ # instances of `~.GridSpec` and `~.SubplotSpec`. * GridSpec* defines a
217+ # (possibly non-uniform) grid of cells. Indexing into the * GridSpec* returns
216218# a SubplotSpec that covers one or more grid cells, and can be used to
217- # specify the location of an Axes or "subplot" .
219+ # specify the location of an * Axes* .
218220#
219- # The following examples show how to use low-level methods to arrange Axes
220- # using GridSpec objects.
221+ # The following examples show how to use low-level methods to arrange * Axes*
222+ # using * GridSpec* objects.
221223#
222224# Basic 2x2 grid
223225# --------------
@@ -238,12 +240,12 @@ def annotate_axes(ax, text, fontsize=18):
238240fig .suptitle ('Manually added subplots using add_gridspec' )
239241
240242##############################################################################
241- # Axes spanning rows or grids in a grid
242- # -------------------------------------
243+ # * Axes* spanning rows or grids in a grid
244+ # ---------------------------------------
243245#
244246# We can index the *spec* array using `NumPy slice syntax
245247# <https://numpy.org/doc/stable/reference/arrays.indexing.html>`_
246- # 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
247249# as ``fig, axd = plt.subplot_mosaic([['ax0', 'ax0'], ['ax1', 'ax2']], ...)``:
248250
249251fig = plt .figure (figsize = (4.5 , 3.5 ), constrained_layout = True )
@@ -257,15 +259,15 @@ def annotate_axes(ax, text, fontsize=18):
257259fig .suptitle ('Manually added subplots, spanning a column' )
258260
259261###############################################################################
260- # Manual adjustments to a GridSpec layout
261- # ---------------------------------------
262+ # Manual adjustments to a * GridSpec* layout
263+ # -----------------------------------------
262264#
263- # When a GridSpec is explicitly used, you can adjust the layout
264- # parameters of subplots that are created from the GridSpec. Note this
265+ # When a * GridSpec* is explicitly used, you can adjust the layout
266+ # parameters of subplots that are created from the * GridSpec* . Note this
265267# option is not compatible with ``constrained_layout`` or
266268# `.Figure.tight_layout` which both ignore *left* and *right* and adjust
267269# subplot sizes to fill the figure. Usually such manual placement
268- # 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* .
269271#
270272# These spacing parameters can also be passed to `~.pyplot.subplots` and
271273# `~.pyplot.subplot_mosaic` as the *gridspec_kw* argument.
@@ -286,7 +288,7 @@ def annotate_axes(ax, text, fontsize=18):
286288# -------------------------------
287289#
288290# You can create nested layout similar to `~.Figure.subfigures` using
289- # `~.gridspec.SubplotSpec.subgridspec`. Here the Axes spines _are_
291+ # `~.gridspec.SubplotSpec.subgridspec`. Here the * Axes* spines _are_
290292# aligned.
291293#
292294# Note this is also available from the more verbose
@@ -313,9 +315,10 @@ def annotate_axes(ax, text, fontsize=18):
313315fig .suptitle ('nested gridspecs' )
314316
315317###############################################################################
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.
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
320+ # the outer 4x4 grid by hiding appropriate spines in each of the inner 3x3
321+ # grids.
319322
320323
321324def squiggle_xy (a , b , c , d , i = np .arange (0.0 , 2 * np .pi , 0.05 )):
0 commit comments