Skip to content

Commit d3c0a50

Browse files
weiji14seisman
andauthored
Apply formatting suggestions from code review
Co-authored-by: Dongdong Tian <[email protected]>
1 parent 6ba4d49 commit d3c0a50

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

examples/tutorials/subplots.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
- Use :meth:`pygmt.Figure.subplot` to define the layout of the subplots.
1414
1515
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
1717
use of :meth:`pygmt.Figure.subplot` which offers finer grained control, and
1818
this is what the tutorial below will cover.
1919
"""
@@ -31,9 +31,9 @@
3131
# Define subplot layout
3232
# ---------------------
3333
#
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,
3535
# 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
3737
# individual subplot. For example:
3838

3939
###############################################################################
@@ -44,30 +44,30 @@
4444

4545
###############################################################################
4646
# 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
4949
# for all subplots instead of setting them individually. The figure layout will
5050
# look like the following:
5151

5252
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+
)
6262
fig.show()
6363

6464
###############################################################################
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
6767
# is similar to matplotlib's ``plt.sca`` method. In order to specify a subplot,
6868
# 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``.
7171

7272
###############################################################################
7373
# .. note::
@@ -78,7 +78,7 @@
7878

7979
###############################################################################
8080
# 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
8282
# there, you can use the following command:
8383

8484
###############################################################################
@@ -91,7 +91,7 @@
9191
# Making your first subplot
9292
# -------------------------
9393
# 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.
9595

9696
fig = pygmt.Figure()
9797
with fig.subplot(
@@ -118,9 +118,9 @@
118118

119119
###############################################################################
120120
# 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:
124124
#
125125
# - ``autolabel=True``: Each subplot is automatically labelled abcd
126126
# - ``margins=["0.1c", "0.2c"]``: adjusts the space between adjacent subplots.
@@ -154,7 +154,7 @@
154154
# --------------------------
155155
# In the example above with the four subplots, the two subplots for each row
156156
# 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
158158
# Y axis between subplots.
159159

160160
fig = pygmt.Figure()

pygmt/src/subplot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def subplot(self, nrows=1, ncols=1, **kwargs):
148148
with Session() as lib:
149149
try:
150150
arg_str = " ".join(["begin", f"{nrows}x{ncols}", build_arg_string(kwargs)])
151-
lib.call_module(module="subplot", args=arg_str)
151+
lib.call_module("subplot", arg_str)
152152
yield
153153
finally:
154154
v_arg = build_arg_string({"V": kwargs.get("V")})

0 commit comments

Comments
 (0)