|
| 1 | +""" |
| 2 | +directional_rose - Add a map directional rose. |
| 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, fmt_docstring |
| 12 | +from pygmt.params import Box, Position |
| 13 | +from pygmt.src._common import _parse_position |
| 14 | + |
| 15 | +__doctest_skip__ = ["directional_rose"] |
| 16 | + |
| 17 | + |
| 18 | +@fmt_docstring |
| 19 | +def directional_rose( |
| 20 | + self, |
| 21 | + position: Position | Sequence[float | str] | AnchorCode | None = None, |
| 22 | + width: float | str | None = None, |
| 23 | + fancy: Literal[1, 2, 3] | bool = False, |
| 24 | + labels: Sequence[str] | bool = False, |
| 25 | + box: Box | bool = False, |
| 26 | + verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] |
| 27 | + | bool = False, |
| 28 | + panel: int | Sequence[int] | bool = False, |
| 29 | + perspective: str | bool = False, |
| 30 | + transparency: float | None = None, |
| 31 | +): |
| 32 | + """ |
| 33 | + Add a directional rose on the map. |
| 34 | +
|
| 35 | + Parameters |
| 36 | + ---------- |
| 37 | + position |
| 38 | + Position of the directional rose on the plot. It can be specified in multiple |
| 39 | + ways: |
| 40 | +
|
| 41 | + - A :class:`pygmt.params.Position` object to fully control the reference point, |
| 42 | + anchor point, and offset. |
| 43 | + - A sequence of two values representing the x and y coordinates in plot |
| 44 | + coordinates, e.g., ``(1, 2)`` or ``("1c", "2c")``. |
| 45 | + - A :doc:`2-character justification code </techref/justification_codes>` for a |
| 46 | + position inside the plot, e.g., ``"TL"`` for Top Left corner inside the plot. |
| 47 | +
|
| 48 | + If not specified, defaults to the bottom-left corner of the plot. |
| 49 | + width |
| 50 | + Width of the rose in plot coordinates, or append unit ``%`` for a size in |
| 51 | + percentage of plot width [Default is 10%]. |
| 52 | + fancy |
| 53 | + Get a fancy rose. The fanciness level can be set to 1, 2, or 3: |
| 54 | +
|
| 55 | + - Level 1 draws the two principal E-W, N-S orientations |
| 56 | + - Level 2 adds the two intermediate NW-SE and NE-SW orientations |
| 57 | + - Level 3 adds the four minor orientations WNW-ESE, NNW-SSE, NNE-SSW, and |
| 58 | + ENE-WSW |
| 59 | +
|
| 60 | + If set to ``True``, defaults to level 1. |
| 61 | + labels |
| 62 | + A sequence of four strings to label the cardinal points W, E, S, N. Use an empty |
| 63 | + string to skip a specific label. If set to ``True``, default labels are used |
| 64 | + (``["W", "E", "S", "N"]`` for a fancy rose and ``["", "", "", "N"]`` for a |
| 65 | + simple rose). |
| 66 | + box |
| 67 | + Draw a background box behind the directional rose. If set to ``True``, a simple |
| 68 | + rectangular box is drawn using :gmt-term:`MAP_FRAME_PEN`. To customize the box |
| 69 | + appearance, pass a :class:`pygmt.params.Box` object to control style, fill, pen, |
| 70 | + and other box properties. |
| 71 | + $verbose |
| 72 | + $panel |
| 73 | + $perspective |
| 74 | + $transparency |
| 75 | +
|
| 76 | + Examples |
| 77 | + -------- |
| 78 | + >>> import pygmt |
| 79 | + >>> fig = pygmt.Figure() |
| 80 | + >>> fig.basemap(region=[0, 80, 0, 30], projection="M10c", frame=True) |
| 81 | + >>> fig.directional_rose() |
| 82 | + >>> fig.show() |
| 83 | + """ |
| 84 | + self._activate_figure() |
| 85 | + |
| 86 | + position = _parse_position( |
| 87 | + position, |
| 88 | + kwdict={"width": width, "fancy": fancy, "labels": labels}, |
| 89 | + default=Position("BL", cstype="inside"), # Default to BL. |
| 90 | + ) |
| 91 | + |
| 92 | + aliasdict = AliasSystem( |
| 93 | + F=Alias(box, name="box"), |
| 94 | + Td=[ |
| 95 | + Alias(position, name="position"), |
| 96 | + Alias(width, name="width", prefix="+w"), |
| 97 | + Alias(fancy, name="fancy", prefix="+f"), |
| 98 | + Alias(labels, name="labels", prefix="+l", sep=",", size=4), |
| 99 | + ], |
| 100 | + ).add_common( |
| 101 | + V=verbose, |
| 102 | + c=panel, |
| 103 | + p=perspective, |
| 104 | + t=transparency, |
| 105 | + ) |
| 106 | + |
| 107 | + with Session() as lib: |
| 108 | + lib.call_module(module="basemap", args=build_arg_list(aliasdict)) |
0 commit comments