88from pygmt ._typing import AnchorCode
99from pygmt .alias import Alias , AliasSystem
1010from pygmt .clib import Session
11- from pygmt .exceptions import GMTInvalidInput
1211from pygmt .helpers import build_arg_list , fmt_docstring
1312from pygmt .params import Box , Position
1413from pygmt .src ._common import _parse_position
1918@fmt_docstring
2019def scalebar ( # noqa: PLR0913
2120 self ,
22- position : Position | Sequence [float | str ] | AnchorCode | None = None ,
23- length : float | str | None = None ,
21+ length : float | str ,
2422 height : float | str | None = None ,
23+ position : Position | Sequence [float | str ] | AnchorCode | None = None ,
2524 scale_at : float | Sequence [float ] | bool = False ,
2625 label : str | bool = False ,
2726 label_alignment : Literal ["left" , "right" , "top" , "bottom" ] | None = None ,
@@ -40,6 +39,12 @@ def scalebar( # noqa: PLR0913
4039
4140 Parameters
4241 ----------
42+ length
43+ Length of the scale bar in km. Append a suffix to specify different units. Valid
44+ units are: **e**: meters; **f**: feet; **k**: kilometers; **M**: statute mile;
45+ **n**: nautical miles; **u**: US Survey foot.
46+ height
47+ Height of the scale bar. Only works when ``fancy=True``. [Default is ``"5p"``].
4348 position
4449 Position of the scale bar on the plot. It can be specified in multiple ways:
4550
@@ -52,12 +57,6 @@ def scalebar( # noqa: PLR0913
5257
5358 If not specified, defaults to the Bottom Left corner of the plot with a 0.2-cm
5459 and 0.4-cm offset in the x- and y-directions, respectively.
55- length
56- Length of the scale bar in km. Append a suffix to specify different units. Valid
57- units are: **e**: meters; **f**: feet; **k**: kilometers; **M**: statute mile;
58- **n**: nautical miles; **u**: US Survey foot.
59- height
60- Height of the scale bar. Only works when ``fancy=True``. [Default is ``"5p"``].
6160 scale_at
6261 Specify the location where the map scale is calculated. It can be:
6362
@@ -100,8 +99,8 @@ def scalebar( # noqa: PLR0913
10099 >>> fig = pygmt.Figure()
101100 >>> fig.basemap(region=[0, 80, -30, 30], projection="M10c", frame=True)
102101 >>> fig.scalebar(
103- ... position=Position((10, 10), cstype="mapcoords"),
104102 ... length=1000,
103+ ... position=Position((10, 10), cstype="mapcoords"),
105104 ... fancy=True,
106105 ... label="Scale",
107106 ... unit=True,
@@ -110,25 +109,13 @@ def scalebar( # noqa: PLR0913
110109 """
111110 self ._activate_figure ()
112111
112+ # Parse the 'position' parameter.
113+ # No need to check conflicts with other parameters since it's a new function.
113114 position = _parse_position (
114115 position ,
115- kwdict = {
116- "length" : length ,
117- "height" : height ,
118- "label_alignment" : label_alignment ,
119- "scale_at" : scale_at ,
120- "fancy" : fancy ,
121- "label" : label ,
122- "unit" : unit ,
123- "vertical" : vertical ,
124- },
125116 default = Position ("BL" , offset = (0.2 , 0.4 )), # Default to "BL" with offset.
126117 )
127118
128- if length is None :
129- msg = "Parameter 'length' must be specified."
130- raise GMTInvalidInput (msg )
131-
132119 aliasdict = AliasSystem (
133120 F = Alias (box , name = "box" ),
134121 L = [
0 commit comments