22scalebar - Add a scale bar.
33"""
44
5+ from collections .abc import Sequence
56from typing import Literal
67
78from pygmt .alias import Alias , AliasSystem
89from pygmt .clib import Session
9- from pygmt .exceptions import GMTInvalidInputError
10+ from pygmt .exceptions import GMTInvalidInput
1011from pygmt .helpers import build_arg_list
1112from pygmt .params import Box , Position
1213
1314
1415def scalebar ( # noqa: PLR0913
1516 self ,
16- position : Position ,
17+ position : Position | None = None ,
1718 length : float | str | None = None ,
18- label_alignment : Literal ["left" , "right" , "top" , "bottom" ] | None = None ,
19- scale_position : float | tuple [float , float ] | bool = False ,
19+ scale_position : float | Sequence [float ] | bool = False ,
2020 label : str | bool = False ,
21- fancy : bool = False ,
21+ label_alignment : Literal [ "left" , "right" , "top" , "bottom" ] | None = None ,
2222 unit : bool = False ,
23+ fancy : bool = False ,
2324 vertical : bool = False ,
2425 box : Box | bool = False ,
25- perspective : str | bool = False ,
2626 verbose : Literal ["quiet" , "error" , "warning" , "timing" , "info" , "compat" , "debug" ]
2727 | bool = False ,
28+ panel : int | Sequence [int ] | bool = False ,
2829 transparency : float | None = None ,
30+ perspective : float | Sequence [float ] | str | bool = False ,
2931):
3032 """
3133 Add a scale bar on the map.
3234
33- The scale bar is plotted at the location defined by the reference point (specified
34- by the **position** and *position_type** parameters) and anchor point (specified by
35- the **anchor** and **anchor_offset** parameters). Refer to
36- :doc:`/techref/reference_anchor_points` for details about the positioning.
37-
3835 Parameters
3936 ----------
4037 position
@@ -59,19 +56,19 @@ def scalebar( # noqa: PLR0913
5956 - ``False``: Default to the location of the reference point.
6057 label
6158 Text string to use as the scale bar label. If ``False``, no label is drawn. If
62- ``True``, the distance unit provided in the ** length** parameter (default is km)
63- is used as the label. The parameter requires ``fancy=True``.
59+ ``True``, the distance unit provided in the `` length` parameter (default is km)
60+ is used as the label. This parameter requires ``fancy=True``.
6461 label_alignment
65- Alignment of the scale bar label. Choose from "left", "right", "top", or
66- " bottom". [Default is "top"].
62+ Alignment of the scale bar label. Choose from `` "left"``, `` "right"``,
63+ ``"top"``, or ``" bottom"`` . [Default is `` "top"`` ].
6764 fancy
68- If ``True``, draw a “ fancy” scale bar. A fancy scale bar is a segmented bar with
69- alternating black and white rectangles. If ``False``, draw a plain scale bar.
65+ If ``True``, draw a " fancy" scale bar, which is a segmented bar with alternating
66+ black and white rectangles. If ``False``, draw a plain scale bar.
7067 unit
7168 If ``True``, append the unit to all distance annotations along the scale. For a
7269 plain scale, this will instead select the unit to be appended to the distance
73- length. The unit is determined from the suffix in the ** length** or defaults to
74- km .
70+ length. The unit is determined from the suffix in the `` length`` or defaults to
71+ ``"km"`` .
7572 vertical
7673 If ``True``, plot a vertical rather than a horizontal Cartesian scale.
7774 box
@@ -98,14 +95,14 @@ def scalebar( # noqa: PLR0913
9895 ... )
9996 >>> fig.show()
10097 """
101- self ._preprocess ()
98+ self ._activate_figure ()
10299
103100 if position is None :
104101 msg = "Parameter 'position' must be specified."
105- raise GMTInvalidInputError (msg )
102+ raise GMTInvalidInput (msg )
106103 if length is None :
107104 msg = "Parameter 'length' must be specified."
108- raise GMTInvalidInputError (msg )
105+ raise GMTInvalidInput (msg )
109106
110107 aliasdict = AliasSystem (
111108 F = Alias (box , name = "box" ),
@@ -124,9 +121,10 @@ def scalebar( # noqa: PLR0913
124121 Alias (unit , name = "unit" , prefix = "+u" ),
125122 Alias (vertical , name = "vertical" , prefix = "+v" ),
126123 ],
127- p = Alias (perspective , name = "perspective" ),
128124 ).add_common (
129125 V = verbose ,
126+ c = panel ,
127+ p = perspective ,
130128 t = transparency ,
131129 )
132130
0 commit comments