Skip to content

Commit 862bd77

Browse files
willschlitzerweiji14seisman
authored
Add tutorial for adding a map title (#720)
Co-authored-by: Wei Ji <[email protected]> Co-authored-by: Dongdong Tian <[email protected]>
1 parent 2128dd4 commit 862bd77

File tree

1 file changed

+53
-4
lines changed

1 file changed

+53
-4
lines changed

examples/tutorials/frames.py

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
# coastlines of the world with a Mercator projection:
1717

1818
fig = pygmt.Figure()
19-
fig.coast(shorelines="1/0.5p", region=[-180, 180, -60, 60], projection="M10i")
19+
fig.coast(shorelines="1/0.5p", region=[-180, 180, -60, 60], projection="M25c")
2020
fig.show()
2121

2222
########################################################################################
2323
# To add the default GMT frame to the plot, use ``frame="f"`` in
2424
# :meth:`pygmt.Figure.basemap` or any other plotting module:
2525

2626
fig = pygmt.Figure()
27-
fig.coast(shorelines="1/0.5p", region=[-180, 180, -60, 60], projection="M10i")
27+
fig.coast(shorelines="1/0.5p", region=[-180, 180, -60, 60], projection="M25c")
2828
fig.basemap(frame="f")
2929
fig.show()
3030

@@ -36,14 +36,63 @@
3636
# and automatically determines tick labels from the plot region.
3737

3838
fig = pygmt.Figure()
39-
fig.coast(shorelines="1/0.5p", region=[-180, 180, -60, 60], projection="M10i")
39+
fig.coast(shorelines="1/0.5p", region=[-180, 180, -60, 60], projection="M25c")
4040
fig.basemap(frame="a")
4141
fig.show()
4242

4343
########################################################################################
4444
# Add automatic grid lines to the plot by adding a ``g`` to ``frame``:
4545

4646
fig = pygmt.Figure()
47-
fig.coast(shorelines="1/0.5p", region=[-180, 180, -60, 60], projection="M10i")
47+
fig.coast(shorelines="1/0.5p", region=[-180, 180, -60, 60], projection="M25c")
4848
fig.basemap(frame="ag")
4949
fig.show()
50+
51+
########################################################################################
52+
# Title
53+
# -----
54+
#
55+
# The figure title can be set by passing **+t**\ *title* to the ``frame`` parameter of
56+
# :meth:`pygmt.Figure.basemap`. Passing multiple arguments to ``frame`` can be done by
57+
# using a list, as show in the example below.
58+
59+
fig = pygmt.Figure()
60+
# region="IS" specifies Iceland using the ISO country code
61+
fig.coast(shorelines="1/0.5p", region="IS", projection="M25c")
62+
fig.basemap(frame=["a", "+tIceland"])
63+
fig.show()
64+
65+
########################################################################################
66+
# To use a title with multiple words, the title must be placed inside another set of
67+
# quotation marks. To prevent the quotation marks from appearing in the figure title,
68+
# the frame argument can be passed in single quotation marks and the title can be
69+
# passed in double quotation marks.
70+
71+
fig = pygmt.Figure()
72+
# region="TT" specifies Trinidad and Tobago
73+
fig.coast(shorelines="1/0.5p", region="TT", projection="M25c")
74+
fig.basemap(frame=["a", '+t"Trinidad and Tobago"'])
75+
fig.show()
76+
77+
########################################################################################
78+
# Axis labels
79+
# -----------
80+
#
81+
# Axis labels can be set by passing **x+l**\ *label* (or starting with y if
82+
# labeling the y-axis) if to the ``frame`` parameter of :meth:`pygmt.Figure.basemap`.
83+
# Axis labels will be displayed on all primary axes, which the default is all sides of
84+
# the figure. To designate only some of the axes as primary, an argument that
85+
# capitlizes only the primary axes can be passed, which is ``"WSne"`` in the example
86+
# below. The letters correspond with west (left), south (bottom), north (top), and
87+
# east (right) sides of a figure.
88+
#
89+
# The example below used a Cartesian projection, as GMT does not allow axis labels to
90+
# be set for geographic maps.
91+
92+
fig = pygmt.Figure()
93+
fig.basemap(
94+
region=[0, 10, 0, 20],
95+
projection="X10c/8c",
96+
frame=["WSne", "x+lx-axis", "y+ly-axis"],
97+
)
98+
fig.show()

0 commit comments

Comments
 (0)