Skip to content

Add Figure.magnetic_rose to plot a magnetic rose on map #4051

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Plotting map elements
Figure.inset
Figure.legend
Figure.logo
Figure.magnetic_rose
Figure.solar
Figure.text
Figure.timestamp
Expand Down
1 change: 1 addition & 0 deletions pygmt/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ def _repr_html_(self) -> str:
inset,
legend,
logo,
magnetic_rose,
meca,
plot,
plot3d,
Expand Down
1 change: 1 addition & 0 deletions pygmt/src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from pygmt.src.inset import inset
from pygmt.src.legend import legend
from pygmt.src.logo import logo
from pygmt.src.magnetic_rose import magnetic_rose
from pygmt.src.makecpt import makecpt
from pygmt.src.meca import meca
from pygmt.src.nearneighbor import nearneighbor
Expand Down
74 changes: 74 additions & 0 deletions pygmt/src/magnetic_rose.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""
magnetic_rose - Add a map magnetic rose.
"""

from collections.abc import Sequence
from typing import Literal

from pygmt._typing import AnchorCode
from pygmt.alias import Alias, AliasSystem
from pygmt.clib import Session
from pygmt.helpers import build_arg_list


def magnetic_rose( # noqa: PLR0913
self,
position: Sequence[str | float] | AnchorCode,
position_type: Literal[
"mapcoords",
"boxcoords",
"plotcoords",
"inside",
"outside",
] = "mapcoords",
width: float | str | None = None,
justify: AnchorCode | None = None,
anchor_offset: Sequence[float | str] | None = None,
labels: Sequence[str] | bool = False,
outer_pen=None,
inner_pen=None,
declination=None,
declination_label=None,
intervals=None,
):
"""
Add a magnetic rose to the map.
"""
self._activate_figure()

_dec = (
(declination, declination_label)
if declination_label is not None
else declination
)

# [+tints]
aliasdict = AliasSystem(
Tm=[
Alias(
position_type,
name="position_type",
mapping={
"mapcoords": "g",
"boxcoords": "n",
"plotcoords": "x",
"inside": "j",
"outside": "J",
},
),
Alias(position, name="position", sep="/", size=2),
Alias(width, name="width", prefix="+w"),
Alias(justify, name="justify", prefix="+j"),
Alias(anchor_offset, name="anchor_offset", prefix="+o", sep="/", size=2),
Alias(labels, name="labels", prefix="+l", sep=",", size=4),
Alias(outer_pen, name="outer_pen", prefix="+p"),
Alias(inner_pen, name="inner_pen", prefix="+i"),
Alias(
_dec, name="declination/declination_label", prefix="+d", sep="/", size=2
),
Alias(intervals, name="intervals", prefix="+t", sep="/", size=(3, 6)),
],
)

with Session() as lib:
lib.call_module(module="basemap", args=build_arg_list(aliasdict))