Skip to content

Commit 59f2b18

Browse files
committed
Add Figure.directional_rose to plot a directional rose on map
1 parent 170f82e commit 59f2b18

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

pygmt/figure.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ def _repr_html_(self) -> str:
435435
coast,
436436
colorbar,
437437
contour,
438+
directional_rose,
438439
grdcontour,
439440
grdimage,
440441
grdview,

pygmt/src/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from pygmt.src.config import config
1111
from pygmt.src.contour import contour
1212
from pygmt.src.dimfilter import dimfilter
13+
from pygmt.src.directional_rose import directional_rose
1314
from pygmt.src.filter1d import filter1d
1415
from pygmt.src.grd2cpt import grd2cpt
1516
from pygmt.src.grd2xyz import grd2xyz

pygmt/src/directional_rose.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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
12+
13+
14+
def directional_rose(
15+
self,
16+
position,
17+
position_type: Literal["user", "justify", "mirror", "normalize", "plot"]
18+
| None = None,
19+
width=None,
20+
fancy: Literal[1, 2, 3] | bool = False,
21+
justify: AnchorCode | None = None,
22+
offset: Sequence[float | str] | None = None,
23+
label: Sequence[str] | bool = False,
24+
):
25+
"""
26+
Add a directional rose to the map.
27+
28+
Parameters
29+
----------
30+
width
31+
Width of the rose in plot coordinates (append **i** (inch),
32+
**cm** (centimeters), or **p** (points)), or append % for a size in percentage
33+
of map width [default is 10%].
34+
label
35+
A sequence of four strings to label the cardinal points W,E,S,N. Use a empty
36+
string to skip a specific label. If set to ``True``, use the default labels
37+
``["W", "E", "S", "N"]``.
38+
39+
Examples
40+
--------
41+
>>> import pygmt
42+
>>> fig = pygmt.Figure()
43+
>>> fig.basemap(region=[0, 80, -30, 30], projection="M10c", frame=True)
44+
>>> fig.directional_rose(position=(10, 10), position_type="user")
45+
>>> fig.show()
46+
"""
47+
self._activate_figure()
48+
49+
aliasdict = AliasSystem(
50+
Td=[
51+
Alias(
52+
position_type,
53+
name="position_type",
54+
mapping={
55+
"user": "g",
56+
"justify": "j",
57+
"mirror": "J",
58+
"normalize": "n",
59+
"plot": "x",
60+
},
61+
),
62+
Alias(position, name="position", separator="/"),
63+
Alias(width, name="width", prefix="+w"),
64+
Alias(fancy, name="fancy", prefix="+f"),
65+
Alias(justify, name="justify", prefix="+j"),
66+
Alias(label, name="label", prefix="+l", separator=",", size=4),
67+
Alias(offset, name="offset", prefix="+o", separator="/", size=[1, 2]),
68+
]
69+
)
70+
71+
with Session() as lib:
72+
lib.call_module(module="basemap", args=build_arg_list(aliasdict))

0 commit comments

Comments
 (0)