Skip to content

Commit a2d151c

Browse files
Figure.coast: Migrate the shorelines parameter to the new alias system and improve docstrings (#4258)
Co-authored-by: Yvonne Fröhlich <94163266+yvonnefroehlich@users.noreply.github.com>
1 parent 48c3c92 commit a2d151c

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

pygmt/src/coast.py

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,14 @@
88
from pygmt.alias import Alias, AliasSystem
99
from pygmt.clib import Session
1010
from pygmt.exceptions import GMTInvalidInput
11-
from pygmt.helpers import (
12-
args_in_kwargs,
13-
build_arg_list,
14-
fmt_docstring,
15-
use_alias,
16-
)
11+
from pygmt.helpers import args_in_kwargs, build_arg_list, fmt_docstring, use_alias
1712
from pygmt.params import Box
1813

1914
__doctest_skip__ = ["coast"]
2015

2116

2217
@fmt_docstring
23-
@use_alias(A="area_thresh", C="lakes", E="dcw", L="map_scale", W="shorelines")
18+
@use_alias(A="area_thresh", C="lakes", E="dcw", L="map_scale")
2419
def coast( # noqa: PLR0913
2520
self,
2621
resolution: Literal[
@@ -30,6 +25,7 @@ def coast( # noqa: PLR0913
3025
water: str | None = None,
3126
rivers: int | str | Sequence[int | str] | None = None,
3227
borders: int | str | Sequence[int | str] | None = None,
28+
shorelines: bool | str | Sequence[int | str] = False,
3329
box: Box | bool = False,
3430
projection: str | None = None,
3531
frame: str | Sequence[str] | bool = False,
@@ -163,15 +159,31 @@ def coast( # noqa: PLR0913
163159
- ``borders=["1/0.5p,red", "2/0.3p,blue,dashed"]``: Draw national boundaries
164160
with a 0.5-point red pen and state boundaries with a 0.3-point dashed blue
165161
pen.
166-
shorelines : bool, int, str, or list
167-
[*level*\ /]\ *pen*.
168-
Draw shorelines [Default is no shorelines]. Append pen attributes
169-
[Default is ``"0.25p,black,solid"``] which apply to all four levels.
170-
To set the pen for a single level, pass a string with *level*\ /*pen*\ ,
171-
where level is 1-4 and represent coastline, lakeshore, island-in-lake shore,
172-
and lake-in-island-in-lake shore. Pass a list of *level*\ /*pen*
173-
strings to ``shorelines`` to set multiple levels. When specific
174-
level pens are set, those not listed will not be drawn.
162+
shorelines
163+
Draw shorelines. Specify the pen attributes for shorelines [Default pen is
164+
``"0.25p,black,solid"``]. Shorelines have four levels; by default, the same pen
165+
is used for all levels. To specify the shoreline level, use the format
166+
*level*\ /*pen*. Pass a sequence of *level*\ /*pen* strings to draw different
167+
shoreline levels with different pens. When specific level pens are set, those
168+
not listed will not be drawn [Default draws all levels]. ``shorelines=True``
169+
draws all levels with the default pen.
170+
171+
Choose from the following shoreline levels:
172+
173+
- ``1``: Coastline
174+
- ``2``: Lakeshore
175+
- ``3``: Island-in-lake shore
176+
- ``4``: Lake-in-island-in-lake shore
177+
178+
Example usage:
179+
180+
- ``shorelines=True``: Draw all shoreline levels with default pen.
181+
- ``shorelines="0.5p,blue"``: Draw all shoreline levels with a 0.5-point blue
182+
pen.
183+
- ``shorelines="1/0.5p,black"``: Draw only coastlines with a 0.5-point black
184+
pen.
185+
- ``shorelines=["1/0.8p,black", "2/0.4p,blue"]``: Draw coastlines with a
186+
0.8-point black pen and lakeshores with a 0.4-point blue pen.
175187
dcw : str or list
176188
*code1,code2,…*\ [**+g**\ *fill*\ ][**+p**\ *pen*\ ][**+z**].
177189
Select painting country polygons from the `Digital Chart of the World
@@ -219,11 +231,12 @@ def coast( # noqa: PLR0913
219231
and kwargs.get("S", water) is None
220232
and kwargs.get("I", rivers) is None
221233
and kwargs.get("N", borders) is None
222-
and not args_in_kwargs(args=["C", "E", "Q", "W"], kwargs=kwargs)
234+
and kwargs.get("W", shorelines) is False
235+
and not args_in_kwargs(args=["C", "E", "Q"], kwargs=kwargs)
223236
):
224237
msg = (
225238
"At least one of the following parameters must be specified: "
226-
"land, water, rivers, borders, lakes, dcw, Q, or shorelines."
239+
"land, water, rivers, borders, shorelines, lakes, dcw, or Q."
227240
)
228241
raise GMTInvalidInput(msg)
229242

@@ -245,6 +258,7 @@ def coast( # noqa: PLR0913
245258
I=Alias(rivers, name="rivers"),
246259
N=Alias(borders, name="borders"),
247260
S=Alias(water, name="water"),
261+
W=Alias(shorelines, name="shorelines"),
248262
).add_common(
249263
B=frame,
250264
J=projection,

0 commit comments

Comments
 (0)