Skip to content

Commit 84fc545

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

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-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: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
TODO
31+
32+
Examples
33+
--------
34+
>>> import pygmt
35+
>>> from pygmt.params import Box
36+
>>> fig = pygmt.Figure()
37+
>>> fig.basemap(region=[0, 80, -30, 30], projection="M10c", frame=True)
38+
>>> fig.directional_rose(
39+
... position=(10, 10),
40+
... position_type="user",
41+
... length=1000,
42+
... fancy=True,
43+
... label="Direction",
44+
... unit=True,
45+
... )
46+
>>> fig.show()
47+
"""
48+
self._preprocess()
49+
50+
aliasdict = AliasSystem(
51+
Td=[
52+
Alias(
53+
position_type,
54+
name="position_type",
55+
mapping={
56+
"user": "g",
57+
"justify": "j",
58+
"mirror": "J",
59+
"normalize": "n",
60+
"plot": "x",
61+
},
62+
),
63+
Alias(position, name="position", separator="/"),
64+
Alias(width, name="width", prefix="+w"),
65+
Alias(fancy, name="fancy", prefix="+f"),
66+
Alias(justify, name="justify", prefix="+j"),
67+
Alias(label, name="label", prefix="+l", separator=",", size=4),
68+
Alias(offset, name="offset", prefix="+o", separator="/", size=[1, 2]),
69+
]
70+
)
71+
72+
with Session() as lib:
73+
lib.call_module(module="basemap", args=build_arg_list(aliasdict))

0 commit comments

Comments
 (0)