GeezerVison is showing github.com — Add Figure.scalebar to plot a scale bar on maps · GenericMappingTools/pygmt@ec9b800
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: pygmt/figure.py +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -449,6 +449,7 @@ def _repr_html_(self) -> str: | 449 | 449 | plot3d, | 450 | 450 | psconvert, | 451 | 451 | rose, | | 452 | + scalebar, | 452 | 453 | set_panel, | 453 | 454 | shift_origin, | 454 | 455 | solar, | |
Collapse file Copy file name to clipboardExpand all lines: pygmt/src/__init__.py +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 43 | 43 | from pygmt.src.project import project | 44 | 44 | from pygmt.src.psconvert import psconvert | 45 | 45 | from pygmt.src.rose import rose | | 46 | +from pygmt.src.scalebar import scalebar | 46 | 47 | from pygmt.src.select import select | 47 | 48 | from pygmt.src.shift_origin import shift_origin | 48 | 49 | from pygmt.src.solar import solar | |
Collapse file Copy file name to clipboard +88Lines changed: 88 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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)) |
|