Skip to content

Commit f4499a8

Browse files
weiji14seisman
andcommitted
Revise advanced subplot layout subsection to use two subplots calls
Co-Authored-By: Dongdong Tian <seisman.info@gmail.com>
1 parent 2f18fe7 commit f4499a8

File tree

1 file changed

+23
-31
lines changed

1 file changed

+23
-31
lines changed

examples/tutorials/subplots.py

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -199,46 +199,38 @@
199199
# the first subplot occupying the first row.
200200

201201
fig = pygmt.Figure()
202-
with fig.subplot(nrows=2, ncols=2, figsize=("15c", "6c"), autolabel=True):
202+
# Bottom row, two subplots
203+
with fig.subplot(nrows=1, ncols=2, figsize=("15c", "3c"), autolabel="b)"):
203204
fig.basemap(
204-
region=[0, 10, 0, 10], projection="X15c/3c", frame=["af", "WSne"], panel=[0, 0]
205+
region=[0, 5, 0, 5], projection="X?", frame=["af", "WSne"], panel=[0, 0]
205206
)
206-
fig.text(text="TEXT", x=5, y=5, projection="X15c/3c")
207207
fig.basemap(
208-
region=[0, 5, 0, 5], projection="X?", frame=["af", "WSne"], panel=[1, 0]
208+
region=[0, 5, 0, 5], projection="X?", frame=["af", "WSne"], panel=[0, 1]
209209
)
210+
# Top row, one subplot
211+
with fig.subplot(
212+
nrows=1, ncols=1, figsize=("15c", "3c"), autolabel="a)", yshift="h+1c"
213+
):
210214
fig.basemap(
211-
region=[0, 5, 0, 5], projection="X?", frame=["af", "WSne"], panel=[1, 1]
215+
region=[0, 10, 0, 10], projection="X?", frame=["af", "WSne"], panel=[0, 0]
212216
)
213-
fig.show()
217+
fig.text(text="TEXT", x=5, y=5)
214218

215-
###############################################################################
216-
#
217-
# When drawing the three basemaps, the last two basemaps use
218-
# ``projection="X?"``, so GMT will automatically determine the size of the
219-
# subplot according to the size of the subplot area. In order for the first
220-
# subplot to fill up the entire top row space, we use manually adjusted the
221-
# subplot width to 15cm using ``projection="X15c/3c"``.
219+
fig.show()
222220

223221
###############################################################################
224-
# .. note::
225-
#
226-
# There are bugs that have not been fixed in the above example.
227-
#
228-
# In subplot mode, the size of each subgraph is controlled by the
229-
# ``figsize`` option of :meth:`pygmt.Figure.subplot`. Users can override
230-
# this and use ``projection`` to specify the size of an individual subplot,
231-
# but this size will not be remembered. If the next command does not
232-
# specify ``projection``, the default size of the subplot mode will be
233-
# used, and the resulting plot will be inccorect.
234222
#
235-
# The current workaround is to use the same ``projection`` option in all
236-
# commands for the subplot. For example, we forced subplot (a) to have a
237-
# different size using ``projection="15c/3c``. The next command within the
238-
# subplot (e.g. ``text``) must also use ``projection="x15c/3c"``, otherwise
239-
# the placement will be wrong.
223+
# We start by drawing the bottom two subplots, setting ``autolabel="b)"`` so
224+
# that the subplots are labelled 'b)' and 'c)'. Then, we plot a single subplot
225+
# on the top row by using ``fig.subplot(..., yshift="h+1c")`` which shifts the
226+
# plot origin 1 cm beyond the **h**\ eight of the previous (bottom row) plot.
227+
# You may need to adjust this ``yshift`` parameter to make your plot look nice.
228+
# This top row uses ``autolabel="a)"``, and we also plotted some text inside.
229+
# Note that ``projection="X?"`` was used to let GMT automatically determine the
230+
# size of the subplot according to the size of the subplot area.
240231

241232
###############################################################################
242-
# Since we skipped the second subplot, the auto label function will name the
243-
# three subplots as a, c and d, which is not what we want, so we have to use
244-
# ``fig.set_panel(..., fixedlabel="(a)")`` to manually set the subplot label.
233+
# You can also manually override the ``autolabel`` for each subplot using for
234+
# example, ``fig.set_panel(..., fixedlabel="b) Panel 2"`` which would allow you
235+
# to manually label a single subplot as you wish. This can be useful for adding
236+
# a more descriptive subtitle to individual subplots.

0 commit comments

Comments
 (0)