Skip to content
Open
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
119 changes: 119 additions & 0 deletions examples/gallery/embellishments/map_roses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
r"""
Directional map roses
=====================

The :meth:`pygmt.Figure.directional_rose` method allows to add
directional roses on maps when using :meth:`pygmt.Figure.basemap`
or :meth:`pygmt.Figure.coast`. This example shows how such a map
rose can be customized.

Colors of the map roses can be adjusted using :gmt-term:`MAP_DEFAULT_PEN`
and :gmt-term:`MAP_TICK_PEN_PRIMARY` via :func:`pygmt.config`. Customizing
label font and color can be done via :gmt-term:`FONT_TITLE`.
"""

# %%
import pygmt
from pygmt.params import Position

fig = pygmt.Figure()

region = [-5, 80, -10, 32]
projection = "M10c"

yval_top = 20
yval_bottom = 0
Comment on lines +24 to +25
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the variable names are easier to read without the "val" (and they are shorter).

Suggested change
yval_top = 20
yval_bottom = 0
y_top = 20
y_bottom = 0

width = "1.5c"

fig.basemap(region=region, projection=projection, frame=True)
Comment on lines +21 to +28
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As now the roses are plotted into one map, variables for region and projection are not directly needed.

Suggested change
region = [-5, 80, -10, 32]
projection = "M10c"
yval_top = 20
yval_bottom = 0
width = "1.5c"
fig.basemap(region=region, projection=projection, frame=True)
yval_top = 20
yval_bottom = 0
width = "1.5c"
fig.basemap(region=[-5, 80, -10, 32], projection="M10c", frame=True)


# Plain rose of 1.5 cm width showing arrow towards north, a cross
# indicating the cardinal directions, and corresponding label
Comment on lines +30 to +31
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Plain rose of 1.5 cm width showing arrow towards north, a cross
# indicating the cardinal directions, and corresponding label
# Plain rose of 1.5 cm width showing an arrow towards North, a cross
# indicating the cardinal directions, and a label for the North direction

fig.directional_rose(
width=width, labels=True, position=Position((0, yval_top), cstype="mapcoords")
)

# Fancy, 1.5 cm wide rose of level 1 and labels indicating the different
# directions
Comment on lines +36 to +37
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should fit into one line.

Suggested change
# Fancy, 1.5 cm wide rose of level 1 and labels indicating the different
# directions
# Fancy, 1.5 cm wide rose of level 1 and labels indicating the different directions

fig.directional_rose(
width=width,
labels=True,
position=Position((20, yval_top), cstype="mapcoords"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
position=Position((20, yval_top), cstype="mapcoords"),
position=Position((20, y_top), cstype="mapcoords"),

fancy=True,
)

# Fancy, 1.5 cm wide rose of level 2 and labels indicating the different
# directions
fig.directional_rose(
width=width,
labels=True,
position=Position((45, yval_top), cstype="mapcoords"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
position=Position((45, yval_top), cstype="mapcoords"),
position=Position((45, y_top), cstype="mapcoords"),

fancy=2,
)

# Fancy, 1.5 cm wide rose of level 3 and labels indicating the different
# directions
fig.directional_rose(
width=width,
labels=True,
position=Position((70, yval_top), cstype="mapcoords"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
position=Position((70, yval_top), cstype="mapcoords"),
position=Position((70, y_top), cstype="mapcoords"),

fancy=3,
)

# Plain rose of 1.5 cm width showing arrow towards north, a cross
# indicating the cardinal directions, and corresponding label.
Comment on lines +63 to +64
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Plain rose of 1.5 cm width showing arrow towards north, a cross
# indicating the cardinal directions, and corresponding label.
# Plain rose of 1.5 cm width showing an arrow towards North, a cross
# indicating the cardinal directions, and a label for the North direction.

# Colors of the rose and labels are defined via
# MAP_TICK_PEN_PRIMARY and FONT_TITLE, respectively
with pygmt.config(MAP_TICK_PEN_PRIMARY="purple", FONT_TITLE="8p,darkmagenta"):
fig.directional_rose(
width=width,
labels=True,
position=Position((0, yval_bottom), cstype="mapcoords"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
position=Position((0, yval_bottom), cstype="mapcoords"),
position=Position((0, y_bottom), cstype="mapcoords"),

)

# Fancy, 1.5 cm wide rose of level 1 with only one label indicating the North
# direction. Colors of the rose and labels are defined via
# MAP_DEFAULT_PEN, MAP_TICK_PEN_PRIMARY and FONT_TITLE, respectively.
with pygmt.config(
MAP_DEFAULT_PEN="default,pink",
MAP_TICK_PEN_PRIMARY="red3",
FONT_TITLE="8p,Bookman-Light,red3",
):
fig.directional_rose(
width=width,
labels=["", "", "", "N"],
position=Position((20, yval_bottom), cstype="mapcoords"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
position=Position((20, yval_bottom), cstype="mapcoords"),
position=Position((20, y_bottom), cstype="mapcoords"),

fancy=True,
)

# Fancy, 1.5 cm wide rose of level 2 with two labels indicating the West and
# East directions. Colors of the rose and labels are defined via
# MAP_DEFAULT_PEN, MAP_TICK_PEN_PRIMARY and FONT_TITLE, respectively
with pygmt.config(
MAP_DEFAULT_PEN="default,lightorange",
MAP_TICK_PEN_PRIMARY="darkorange",
FONT_TITLE="8p,Bookman-Light,darkorange",
):
fig.directional_rose(
width=width,
labels=["W", "E", "", ""],
position=Position((45, yval_bottom), cstype="mapcoords"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
position=Position((45, yval_bottom), cstype="mapcoords"),
position=Position((45, y_bottom), cstype="mapcoords"),

fancy=2,
)

# Fancy, 1.5 cm wide rose of level 3 with two labels indicating the North and
# South directions. Colors of the rose and labels are defined via
# MAP_DEFAULT_PEN, MAP_TICK_PEN_PRIMARY and FONT_TITLE, respectively
with pygmt.config(
MAP_DEFAULT_PEN="default,Dodgerblue4",
MAP_TICK_PEN_PRIMARY="Dodgerblue",
FONT_TITLE="8p,AvantGarde-Demi,Dodgerblue4",
):
fig.directional_rose(
width=width,
labels=["", "", "South", "North"],
position=Position((70, yval_bottom), cstype="mapcoords"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
position=Position((70, yval_bottom), cstype="mapcoords"),
position=Position((70, y_bottom), cstype="mapcoords"),

fancy=3,
)

fig.show()
Loading