-
Notifications
You must be signed in to change notification settings - Fork 235
Add Figure.directional_rose to plot a directional rose on map #4025
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
7ba2bda
Add Figure.directional_rose for adding directional rose on maps
seisman 9ab906c
Fix typos
seisman 93993d3
Fix typos
seisman c5e8af7
Merge branch 'main' into feature/direction_rose
seisman 8b72a1e
Merge branch 'main' into feature/direction_rose
seisman e9fef83
Merge branch 'main' into feature/direction_rose
seisman 4adcc26
Pass an empty dict to kwdict
seisman 6f8d0e9
Merge branch 'main' into feature/direction_rose
seisman 391eed0
Simplify _parse_position
seisman 434b145
Merge branch 'main' into feature/direction_rose
seisman 30f5e50
Merge branch 'main' into feature/direction_rose
seisman 39dd721
Merge branch 'main' into feature/direction_rose
seisman f5090de
Document that Figure.basemap's rose parameter is deprecated
seisman 6d94ba8
Update pygmt/tests/test_inset.py
seisman e0bddc9
Update pygmt/tests/test_directional_rose.py
seisman 47a58b2
Fix docstrings
seisman 8d70181
Merge branch 'main' into feature/direction_rose
seisman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| """ | ||
| directional_rose - Add a map directional 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, fmt_docstring | ||
| from pygmt.params import Box, Position | ||
| from pygmt.src._common import _parse_position | ||
|
|
||
| __doctest_skip__ = ["directional_rose"] | ||
|
|
||
|
|
||
| @fmt_docstring | ||
| def directional_rose( | ||
| self, | ||
| position: Position | Sequence[float | str] | AnchorCode | None = None, | ||
| width: float | str | None = None, | ||
| fancy: Literal[1, 2, 3] | bool = False, | ||
| labels: Sequence[str] | bool = False, | ||
| box: Box | bool = False, | ||
| verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"] | ||
| | bool = False, | ||
| panel: int | Sequence[int] | bool = False, | ||
| perspective: str | bool = False, | ||
| transparency: float | None = None, | ||
| ): | ||
| """ | ||
| Add a directional rose on the map. | ||
|
|
||
| Parameters | ||
seisman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ---------- | ||
| position | ||
| Position of the directional rose on the plot. It can be specified in multiple | ||
| ways: | ||
|
|
||
| - A :class:`pygmt.params.Position` object to fully control the reference point, | ||
| anchor point, and offset. | ||
| - A sequence of two values representing the x- and y-coordinates in plot | ||
| coordinates, e.g., ``(1, 2)`` or ``("1c", "2c")``. | ||
| - A :doc:`2-character justification code </techref/justification_codes>` for a | ||
| position inside the plot, e.g., ``"TL"`` for Top Left corner inside the plot. | ||
|
|
||
| If not specified, defaults to the Bottom Left corner of the plot. | ||
| width | ||
| Width of the rose in plot coordinates, or append unit ``%`` for a size in | ||
| percentage of plot width [Default is 10%]. | ||
| fancy | ||
| Get a fancy rose. The fanciness level can be set to 1, 2, or 3: | ||
|
|
||
| - Level 1 draws the two principal E-W, N-S orientations | ||
| - Level 2 adds the two intermediate NW-SE and NE-SW orientations | ||
| - Level 3 adds the four minor orientations WNW-ESE, NNW-SSE, NNE-SSW, and | ||
| ENE-WSW | ||
|
|
||
| If set to ``True``, defaults to level 1. | ||
| labels | ||
| A sequence of four strings to label the cardinal points W, E, S, N. Use an empty | ||
| string to skip a specific label. If set to ``True``, default labels are used | ||
| (``["W", "E", "S", "N"]`` for a fancy rose and ``["", "", "", "N"]`` for a | ||
| simple rose). | ||
| box | ||
| Draw a background box behind the directional rose. If set to ``True``, a simple | ||
| rectangular box is drawn using :gmt-term:`MAP_FRAME_PEN`. To customize the box | ||
| appearance, pass a :class:`pygmt.params.Box` object to control style, fill, pen, | ||
| and other box properties. | ||
| $verbose | ||
| $panel | ||
| $perspective | ||
| $transparency | ||
|
|
||
| Examples | ||
| -------- | ||
| >>> import pygmt | ||
| >>> fig = pygmt.Figure() | ||
| >>> fig.basemap(region=[0, 80, 0, 30], projection="M10c", frame=True) | ||
| >>> fig.directional_rose() | ||
| >>> fig.show() | ||
| """ | ||
| self._activate_figure() | ||
|
|
||
| position = _parse_position(position, default=Position("BL", cstype="inside")) | ||
|
|
||
| aliasdict = AliasSystem( | ||
| F=Alias(box, name="box"), | ||
| Td=[ | ||
| Alias(position, name="position"), | ||
| Alias(width, name="width", prefix="+w"), | ||
| Alias(fancy, name="fancy", prefix="+f"), | ||
| Alias(labels, name="labels", prefix="+l", sep=",", size=4), | ||
| ], | ||
| ).add_common( | ||
| V=verbose, | ||
| c=panel, | ||
| p=perspective, | ||
| t=transparency, | ||
| ) | ||
|
|
||
| with Session() as lib: | ||
| lib.call_module(module="basemap", args=build_arg_list(aliasdict)) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| outs: | ||
| - md5: c1c167a826132bcdabc3b032438db01e | ||
| size: 8319 | ||
| hash: md5 | ||
| path: test_directional_rose.png |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| outs: | ||
| - md5: 7a7eabd0036dc9b744e54dfbc398fc6e | ||
| size: 9772 | ||
| hash: md5 | ||
| path: test_directional_rose_complex.png |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| outs: | ||
| - md5: 7498ed12efd8b956a0fe13d18e0e3ea9 | ||
| size: 8648 | ||
| hash: md5 | ||
| path: test_directional_rose_fancy.png |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| """ | ||
| Test Figure.directional_rose. | ||
| """ | ||
|
|
||
| import pytest | ||
| from pygmt import Figure | ||
| from pygmt.params import Position | ||
|
|
||
|
|
||
| @pytest.mark.mpl_image_compare | ||
| def test_directional_rose(): | ||
| """ | ||
| Test the Figure.directional_rose method with default position and width. | ||
| """ | ||
| fig = Figure() | ||
| fig.basemap(region=[0, 80, 0, 30], projection="M10c", frame=True) | ||
| fig.directional_rose() | ||
| return fig | ||
|
|
||
|
|
||
| @pytest.mark.mpl_image_compare | ||
| def test_directional_rose_fancy(): | ||
| """ | ||
| Test the Figure.directional_rose method with the fancy style enabled. | ||
| """ | ||
| fig = Figure() | ||
| fig.basemap(region=[0, 80, 0, 30], projection="M10c", frame=True) | ||
| fig.directional_rose(fancy=True) | ||
| return fig | ||
|
|
||
|
|
||
| @pytest.mark.mpl_image_compare | ||
| def test_directional_rose_complex(): | ||
| """ | ||
| Test the Figure.directional_rose method with more parameters. | ||
| """ | ||
| fig = Figure() | ||
| fig.basemap(region=[0, 80, 0, 30], projection="M10c", frame=True) | ||
| fig.directional_rose( | ||
| position=Position((50, 0), cstype="mapcoords", anchor="MC", offset=(1, 1)), | ||
| width="1c", | ||
| labels=["", "", "", "N"], | ||
| fancy=2, | ||
| ) | ||
| return fig |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.