|
| 1 | +""" |
| 2 | +scalebar - Add a scale bar. |
| 3 | +""" |
| 4 | + |
| 5 | +from collections.abc import Sequence |
| 6 | +from typing import Literal |
| 7 | + |
| 8 | +from pygmt._typing import AnchorCode |
| 9 | +from pygmt.alias import Alias, AliasSystem |
| 10 | +from pygmt.clib import Session |
| 11 | +from pygmt.helpers import build_arg_list |
| 12 | + |
| 13 | + |
| 14 | +def scalebar( # noqa: PLR0913 |
| 15 | + self, |
| 16 | + position, |
| 17 | + length, |
| 18 | + position_type: Literal["user", "justify", "mirror", "normalize", "plot"] |
| 19 | + | None = None, |
| 20 | + label_alignment: Literal["left", "right", "top", "bottom"] | None = None, |
| 21 | + scale_position=None, |
| 22 | + justify: AnchorCode | None = None, |
| 23 | + offset: Sequence[float | str] | None = None, |
| 24 | + label: str | bool = False, |
| 25 | + fancy: bool = False, |
| 26 | + unit: bool = False, |
| 27 | + vertical: bool = False, |
| 28 | + box=None, |
| 29 | +): |
| 30 | + """ |
| 31 | + Add a scale bar. |
| 32 | +
|
| 33 | + Parameters |
| 34 | + ---------- |
| 35 | + TODO |
| 36 | +
|
| 37 | + Examples |
| 38 | + -------- |
| 39 | + >>> import pygmt |
| 40 | + >>> from pygmt.params import Box |
| 41 | + >>> fig = pygmt.Figure() |
| 42 | + >>> fig.basemap(region=[0, 80, -30, 30], projection="M10c", frame=True) |
| 43 | + >>> fig.scalebar( |
| 44 | + ... position=(10, 10), |
| 45 | + ... position_type="user", |
| 46 | + ... length=1000, |
| 47 | + ... fancy=True, |
| 48 | + ... label="Scale", |
| 49 | + ... unit=True, |
| 50 | + ... ) |
| 51 | + >>> fig.show() |
| 52 | + """ |
| 53 | + self._preprocess() |
| 54 | + |
| 55 | + aliasdict = AliasSystem( |
| 56 | + L=[ |
| 57 | + Alias( |
| 58 | + position_type, |
| 59 | + name="position_type", |
| 60 | + mapping={ |
| 61 | + "user": "g", |
| 62 | + "justify": "j", |
| 63 | + "mirror": "J", |
| 64 | + "normalize": "n", |
| 65 | + "plot": "x", |
| 66 | + }, |
| 67 | + ), |
| 68 | + Alias(position, name="position", separator="/"), |
| 69 | + Alias(length, name="length", prefix="+w"), |
| 70 | + Alias( |
| 71 | + label_alignment, |
| 72 | + name="label_alignment", |
| 73 | + prefix="+a", |
| 74 | + mapping={"left": "l", "right": "r", "top": "t", "bottom": "b"}, |
| 75 | + ), |
| 76 | + Alias(scale_position, name="scale_position", prefix="+c", separator="/"), |
| 77 | + Alias(fancy, name="fancy", prefix="+f"), |
| 78 | + Alias(justify, name="justify", prefix="+j"), |
| 79 | + Alias(label, name="label", prefix="+l"), |
| 80 | + Alias(offset, name="offset", prefix="+o", separator="/", size=[1, 2]), |
| 81 | + Alias(unit, name="unit", prefix="+u"), |
| 82 | + Alias(vertical, name="vertical", prefix="+v"), |
| 83 | + ], |
| 84 | + F=Alias(box, name="box"), |
| 85 | + ) |
| 86 | + |
| 87 | + with Session() as lib: |
| 88 | + lib.call_module(module="basemap", args=build_arg_list(aliasdict)) |
0 commit comments