|
| 1 | +""" |
| 2 | +scalebar - Add a scale bar. |
| 3 | +""" |
| 4 | + |
| 5 | +from typing import Literal |
| 6 | + |
| 7 | +from pygmt.alias import Alias, AliasSystem |
| 8 | +from pygmt.clib import Session |
| 9 | +from pygmt.helpers import build_arg_list |
| 10 | + |
| 11 | + |
| 12 | +def scalebar( # noqa: PLR0913 |
| 13 | + self, |
| 14 | + position, |
| 15 | + length, |
| 16 | + position_type: Literal[ |
| 17 | + "user", "justify", "mirror", "normalize", "plot", None |
| 18 | + ] = None, |
| 19 | + label_alignment=None, |
| 20 | + scale_position=None, |
| 21 | + fancy=None, |
| 22 | + justify=None, |
| 23 | + label=None, |
| 24 | + offset=None, |
| 25 | + unit=None, |
| 26 | + vertical=None, |
| 27 | + box=None, |
| 28 | +): |
| 29 | + """ |
| 30 | + Add a scale bar. |
| 31 | +
|
| 32 | + Parameters |
| 33 | + ---------- |
| 34 | + TODO |
| 35 | +
|
| 36 | + Examples |
| 37 | + -------- |
| 38 | + >>> import pygmt |
| 39 | + >>> from pygmt.params import Box |
| 40 | + >>> fig = pygmt.Figure() |
| 41 | + >>> fig.basemap(region=[0, 80, -30, 30], projection="M10c", frame=True) |
| 42 | + >>> fig.scalebar( |
| 43 | + ... position=(10, 10), |
| 44 | + ... position_type="g", |
| 45 | + ... length=1000, |
| 46 | + ... fancy=True, |
| 47 | + ... label="Scale", |
| 48 | + ... unit=True, |
| 49 | + ... box=Box(pen=0.5, fill="lightblue"), |
| 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(label_alignment, name="label_alignment", prefix="+a"), |
| 71 | + Alias(scale_position, name="scale_position", prefix="+c", separator="/"), |
| 72 | + Alias(fancy, name="fancy", prefix="+f"), |
| 73 | + Alias(justify, name="justify", prefix="+j"), |
| 74 | + Alias(label, name="label", prefix="+l"), |
| 75 | + Alias(offset, name="offset", prefix="+o", separator="/"), |
| 76 | + Alias(unit, name="unit", prefix="+u"), |
| 77 | + Alias(vertical, name="vertical", prefix="+v"), |
| 78 | + ], |
| 79 | + F=Alias(box, name="box"), |
| 80 | + ) |
| 81 | + |
| 82 | + with Session() as lib: |
| 83 | + lib.call_module(module="basemap", args=build_arg_list(aliasdict)) |
0 commit comments