22scalebar - Add a scale bar.
33"""
44
5- from collections .abc import Sequence
65from typing import Literal
76
8- from pygmt ._typing import AnchorCode
97from pygmt .alias import Alias , AliasSystem
108from pygmt .clib import Session
119from pygmt .exceptions import GMTInvalidInputError
1210from pygmt .helpers import build_arg_list
13- from pygmt .params import Box
11+ from pygmt .params import Box , Position
1412
1513
1614def scalebar ( # noqa: PLR0913
1715 self ,
18- position : Sequence [float | str ] | AnchorCode | None = None ,
19- position_type : Literal [
20- "mapcoords" , "boxcoords" , "plotcoords" , "inside" , "outside"
21- ] = "plotcoords" ,
22- anchor : AnchorCode | None = None ,
23- anchor_offset : Sequence [float | str ] | None = None ,
16+ position : Position ,
2417 length : float | str | None = None ,
2518 label_alignment : Literal ["left" , "right" , "top" , "bottom" ] | None = None ,
2619 scale_position : float | tuple [float , float ] | bool = False ,
@@ -44,40 +37,9 @@ def scalebar( # noqa: PLR0913
4437
4538 Parameters
4639 ----------
47- position/position_type
48- Specify the reference point on the map for the directional rose. The reference
49- point can be specified in five different ways, which is selected by the
50- **position_type** parameter. The actual reference point is then given by the
51- coordinates or code specified by the **position** parameter.
52-
53- The **position_type** parameter can be one of the following:
54-
55- - ``"mapcoords"``: **position** is given as (*longitude*, *latitude*) in map
56- coordinates.
57- - ``"boxcoords"``: **position** is given as (*nx*, *ny*) in normalized
58- coordinates, i.e., fractional coordinates between 0 and 1 in both the x and y
59- directions. For example, (0, 0) is the lower-left corner and (1, 1) is the
60- upper-right corner of the plot bounding box.
61- - ``"plotcoords"``: **position** is given as (x, y) in plot coordinates, i.e.,
62- the distances in inches, centimeters, or points from the lower left plot
63- origin.
64- - ``"inside"`` or ``"outside"``: **position** is one of the nine
65- :doc:`2-character justification codes </techref/justification_codes>`, meaning
66- placing the reference point at specific locations, either inside or outside
67- the plot bounding box.
68- anchor
69- Anchor point of the directional rose, specified by one of the
70- :doc:`2-character justification codes </techref/justification_codes>`.
71- The default value depends on the **position_type** parameter.
72-
73- - ``position_type="inside"``: **anchor** defaults to the same as **position**.
74- - ``position_type="outside"``: **anchor** defaults to the mirror opposite of
75- **position**.
76- - Otherwise, **anchor** defaults to ``"MC"`` (middle center).
77- anchor_offset
78- *offset* or (*offset_x*, *offset_y*).
79- Offset the anchor point by *offset_x* and *offset_y*. If a single value *offset*
80- is given, *offset_y* = *offset_x* = *offset*.
40+ position
41+ Specify the location of the scale bar. See :class:`pygmt.params.Position` for
42+ more details.
8143 length
8244 Length of the scale bar in km. You can append different units to the length,
8345 which are:
@@ -117,19 +79,18 @@ def scalebar( # noqa: PLR0913
11779 rectangular box is drawn using :gmt-term:`MAP_FRAME_PEN`. To customize the box
11880 appearance, pass a :class:`pygmt.params.Box` object to control style, fill, pen,
11981 and other box properties.
120- { perspective}
121- { verbose}
122- { transparency}
82+ $ perspective
83+ $ verbose
84+ $ transparency
12385
12486 Examples
12587 --------
12688 >>> import pygmt
127- >>> from pygmt.params import Box
89+ >>> from pygmt.params import Box, Position
12890 >>> fig = pygmt.Figure()
12991 >>> fig.basemap(region=[0, 80, -30, 30], projection="M10c", frame=True)
13092 >>> fig.scalebar(
131- ... position=(10, 10),
132- ... position_type="mapcoords",
93+ ... position=Position((10, 10)),
13394 ... length=1000,
13495 ... fancy=True,
13596 ... label="Scale",
@@ -149,20 +110,7 @@ def scalebar( # noqa: PLR0913
149110 aliasdict = AliasSystem (
150111 F = Alias (box , name = "box" ),
151112 L = [
152- Alias (
153- position_type ,
154- name = "position_type" ,
155- mapping = {
156- "mapcoords" : "g" ,
157- "boxcoords" : "n" ,
158- "plotcoords" : "x" ,
159- "inside" : "j" ,
160- "outside" : "J" ,
161- },
162- ),
163- Alias (position , name = "position" , sep = "/" , size = 2 ),
164- Alias (anchor , name = "justify" , prefix = "+j" ),
165- Alias (anchor_offset , name = "anchor_offset" , prefix = "+o" , sep = "/" , size = 2 ),
113+ Alias (position , name = "position" ),
166114 Alias (length , name = "length" , prefix = "+w" ),
167115 Alias (
168116 label_alignment ,
0 commit comments