|
13 | 13 | - Use :meth:`pygmt.Figure.subplot` to define the layout of the subplots.
|
14 | 14 |
|
15 | 15 | The first method is easier to use and should handle simple cases involving a
|
16 |
| -couple of subplots. For more advanced subplot layouts however, we recommend the |
| 16 | +couple of subplots. For more advanced subplot layouts, however, we recommend the |
17 | 17 | use of :meth:`pygmt.Figure.subplot` which offers finer grained control, and
|
18 | 18 | this is what the tutorial below will cover.
|
19 | 19 | """
|
|
31 | 31 | # Define subplot layout
|
32 | 32 | # ---------------------
|
33 | 33 | #
|
34 |
| -# The :meth:`pygmt.Figure.subplot` command is used to setup the layout, size, |
| 34 | +# The :meth:`pygmt.Figure.subplot` function is used to set up the layout, size, |
35 | 35 | # and other attributes of the figure. It divides the whole canvas into regular
|
36 |
| -# grid areas with n rows and m columns. Each grid area can contain an |
| 36 | +# grid areas with *n* rows and *m* columns. Each grid area can contain an |
37 | 37 | # individual subplot. For example:
|
38 | 38 |
|
39 | 39 | ###############################################################################
|
|
44 | 44 |
|
45 | 45 | ###############################################################################
|
46 | 46 | # will define our figure to have a 2 row and 3 column grid layout.
|
47 |
| -# ``figsize=("15c", "6c")`` defines the overall size of the figure to be 15cm |
48 |
| -# wide by 6cm high. Using ``frame="lrtb"`` allows us to customize the map frame |
| 47 | +# ``figsize=("15c", "6c")`` defines the overall size of the figure to be 15 cm |
| 48 | +# wide by 6 cm high. Using ``frame="lrtb"`` allows us to customize the map frame |
49 | 49 | # for all subplots instead of setting them individually. The figure layout will
|
50 | 50 | # look like the following:
|
51 | 51 |
|
52 | 52 | with fig.subplot(nrows=2, ncols=3, figsize=("15c", "6c"), frame="lrtb"):
|
53 |
| - for index in range(2 * 3): |
54 |
| - i = index // 3 # row |
55 |
| - j = index % 3 # column |
56 |
| - with fig.set_panel(panel=index): # sets the current panel |
57 |
| - fig.text( |
58 |
| - position="MC", |
59 |
| - text=f"index: {index}, row: {i}, col: {j}", |
60 |
| - region=[0, 1, 0, 1], |
61 |
| - ) |
| 53 | + for i in range(2): # row number starting from 0 |
| 54 | + for j in range(3): # column number starting from 0 |
| 55 | + index = i * 3 + j # index number starting from 0 |
| 56 | + with fig.set_panel(panel=index): # sets the current panel |
| 57 | + fig.text( |
| 58 | + position="MC", |
| 59 | + text=f"index: {index}; row: {i}, col: {j}", |
| 60 | + region=[0, 1, 0, 1], |
| 61 | + ) |
62 | 62 | fig.show()
|
63 | 63 |
|
64 | 64 | ###############################################################################
|
65 |
| -# The :meth:`pygmt.Figure.set_panel` command activates a specified subplot, and |
66 |
| -# all subsequent plotting commands will take place in that subplot panel. This |
| 65 | +# The :meth:`pygmt.Figure.set_panel` function activates a specified subplot, and |
| 66 | +# all subsequent plotting functions will take place in that subplot panel. This |
67 | 67 | # is similar to matplotlib's ``plt.sca`` method. In order to specify a subplot,
|
68 | 68 | # you will need to provide the identifier for that subplot via the ``panel``
|
69 |
| -# argument. Pass in either the ``index`` number, or a tuple like |
70 |
| -# (``row``, ``col``) to ``panel``. |
| 69 | +# argument. Pass in either the *index* number, or a tuple/list like |
| 70 | +# (*row*, *col*) to ``panel``. |
71 | 71 |
|
72 | 72 | ###############################################################################
|
73 | 73 | # .. note::
|
|
78 | 78 |
|
79 | 79 | ###############################################################################
|
80 | 80 | # For example, to activate the subplot on the top right corner (index: 2) at
|
81 |
| -# ``row=0`` and ``col=2``, so that all subsequent plotting commands happen |
| 81 | +# *row*\=0 and *col*\=2, so that all subsequent plotting commands happen |
82 | 82 | # there, you can use the following command:
|
83 | 83 |
|
84 | 84 | ###############################################################################
|
|
91 | 91 | # Making your first subplot
|
92 | 92 | # -------------------------
|
93 | 93 | # Next, let's use what we learned above to make a 2 row by 2 column subplot
|
94 |
| -# figure. We'll also pick up on some new parameters to configure our subplot. |
| 94 | +# figure. We'll also pick up on some new arguments to configure our subplot. |
95 | 95 |
|
96 | 96 | fig = pygmt.Figure()
|
97 | 97 | with fig.subplot(
|
|
118 | 118 |
|
119 | 119 | ###############################################################################
|
120 | 120 | # In this example, we define a 2-row, 2-column (2x2) subplot layout using
|
121 |
| -# :meth:`pygmt.Figure.subplot`. The overall figure dimensions is set to be 15cm |
122 |
| -# wide and 6cm high (``figsize=["15c", "6c"]``). In addition, we used some |
123 |
| -# optional parameters to fine tune some details of the figure creation: |
| 121 | +# :meth:`pygmt.Figure.subplot`. The overall figure dimensions is set to be 15 cm |
| 122 | +# wide and 6 cm high (``figsize=["15c", "6c"]``). In addition, we use some |
| 123 | +# optional arguments to fine-tune some details of the figure creation: |
124 | 124 | #
|
125 | 125 | # - ``autolabel=True``: Each subplot is automatically labelled abcd
|
126 | 126 | # - ``margins=["0.1c", "0.2c"]``: adjusts the space between adjacent subplots.
|
|
154 | 154 | # --------------------------
|
155 | 155 | # In the example above with the four subplots, the two subplots for each row
|
156 | 156 | # have the same Y-axis range, and the two subplots for each column have the
|
157 |
| -# same X-axis range. You can use the **layout** option to set a common X and/or |
| 157 | +# same X-axis range. You can use the ``layout`` argument to set a common X and/or |
158 | 158 | # Y axis between subplots.
|
159 | 159 |
|
160 | 160 | fig = pygmt.Figure()
|
|
0 commit comments