Skip to content

Commit 4e9b643

Browse files
authored
Merge branch 'main' into copilot/update-figure-map-usage
2 parents 4660546 + 0bb6ba6 commit 4e9b643

84 files changed

Lines changed: 986 additions & 183 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

doc/api/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Plotting figure elements
3434
Figure.legend
3535
Figure.logo
3636
Figure.magnetic_rose
37+
Figure.paragraph
3738
Figure.scalebar
3839
Figure.solar
3940
Figure.text
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
"""
2+
Directional map rose
3+
====================
4+
5+
The :meth:`pygmt.Figure.directional_rose` method allows to add directional roses on
6+
maps. Using the method without any arguments will plot a rose at the bottom left corner,
7+
but this example will focus on customizing its position and appearance.
8+
9+
Colors of the map roses can be adjusted using :gmt-term:`MAP_DEFAULT_PEN` and
10+
:gmt-term:`MAP_TICK_PEN_PRIMARY` via :func:`pygmt.config`. Customizing label font and
11+
color can be done via :gmt-term:`FONT_TITLE`.
12+
"""
13+
14+
# %%
15+
import pygmt
16+
from pygmt.params import Position
17+
18+
fig = pygmt.Figure()
19+
20+
y0 = 20
21+
y1 = -5
22+
width = "1.5c"
23+
24+
fig.basemap(region=[-5, 80, -17, 32], projection="M10c", frame=True)
25+
26+
# Plain rose of 1.5 cm width showing an arrow towards North, a cross indicating the
27+
# cardinal directions, and a label for the North direction
28+
fig.directional_rose(
29+
width=width, labels=True, position=Position((0, y0), cstype="mapcoords")
30+
)
31+
32+
# Fancy, 1.5 cm wide rose of level 1 and labels indicating the different directions
33+
fig.directional_rose(
34+
width=width,
35+
labels=True,
36+
position=Position((20, y0), cstype="mapcoords"),
37+
fancy=True,
38+
)
39+
40+
# Fancy, 1.5 cm wide rose of level 2 and labels indicating the different directions
41+
fig.directional_rose(
42+
width=width,
43+
labels=True,
44+
position=Position((45, y0), cstype="mapcoords"),
45+
fancy=2,
46+
)
47+
48+
# Fancy, 1.5 cm wide rose of level 3 and labels indicating the different directions
49+
fig.directional_rose(
50+
width=width,
51+
labels=True,
52+
position=Position((70, y0), cstype="mapcoords"),
53+
fancy=3,
54+
)
55+
56+
# Plain rose of 1.5 cm width showing an arrow towards North, a cross indicating the
57+
# cardinal directions, and a label for the North direction. Colors of the rose and
58+
# labels are defined via MAP_TICK_PEN_PRIMARY and FONT_TITLE, respectively
59+
with pygmt.config(MAP_TICK_PEN_PRIMARY="purple", FONT_TITLE="8p,darkmagenta"):
60+
fig.directional_rose(
61+
width=width,
62+
labels=True,
63+
position=Position((0, y1), cstype="mapcoords"),
64+
)
65+
66+
# Fancy, 1.5 cm wide rose of level 1 with only one label indicating the North direction.
67+
# Colors of the rose and labels are defined via MAP_DEFAULT_PEN, MAP_TICK_PEN_PRIMARY
68+
# and FONT_TITLE, respectively.
69+
with pygmt.config(
70+
MAP_DEFAULT_PEN="default,pink",
71+
MAP_TICK_PEN_PRIMARY="red3",
72+
FONT_TITLE="8p,Bookman-Light,red3",
73+
):
74+
fig.directional_rose(
75+
width=width,
76+
labels=["", "", "", "N"],
77+
position=Position((20, y1), cstype="mapcoords"),
78+
fancy=True,
79+
)
80+
81+
# Fancy, 1.5 cm wide rose of level 2 with two labels indicating the West and East
82+
# directions
83+
with pygmt.config(
84+
MAP_DEFAULT_PEN="default,lightorange",
85+
MAP_TICK_PEN_PRIMARY="darkorange",
86+
FONT_TITLE="8p,Bookman-Light,darkorange",
87+
):
88+
fig.directional_rose(
89+
width=width,
90+
labels=["W", "E", "", ""],
91+
position=Position((45, y1), cstype="mapcoords"),
92+
fancy=2,
93+
)
94+
95+
# Fancy, 1.5 cm wide rose of level 3 with two labels indicating the North and South
96+
# directions
97+
with pygmt.config(
98+
MAP_DEFAULT_PEN="default,Dodgerblue4",
99+
MAP_TICK_PEN_PRIMARY="Dodgerblue",
100+
FONT_TITLE="8p,AvantGarde-Demi,Dodgerblue4",
101+
):
102+
fig.directional_rose(
103+
width=width,
104+
labels=["", "", "South", "North"],
105+
position=Position((70, y1), cstype="mapcoords"),
106+
fancy=3,
107+
)
108+
109+
fig.show()

examples/gallery/embellishments/timestamp.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import os
1313

1414
import pygmt
15+
from pygmt.params import Axis
1516

1617
fig = pygmt.Figure()
1718
fig.basemap(region=[20, 30, -10, 10], projection="X10c/5c", frame=True)
@@ -25,7 +26,13 @@
2526
os.environ["TZ"] = "Pacific/Honolulu" # optionally set the time zone
2627

2728
fig = pygmt.Figure()
28-
fig.coast(region="d", projection="H10c", land="black", water="cornsilk", frame="afg")
29+
fig.coast(
30+
region="d",
31+
projection="H10c",
32+
land="black",
33+
water="cornsilk",
34+
frame=Axis(annot=True, tick=True, grid=True),
35+
)
2936
fig.timestamp(
3037
label="Powered by PyGMT",
3138
justify="TL",

examples/gallery/histograms/histogram.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# %%
1212
import numpy as np
1313
import pygmt
14+
from pygmt.params import Axis, Frame
1415

1516
# Generate random elevation data from a normal distribution
1617
rng = np.random.default_rng(seed=100)
@@ -23,9 +24,15 @@
2324

2425
fig.histogram(
2526
data=data,
26-
# Define the frame, add a title, and set the background color to
27-
# "lightgray". Add labels to the x-axis and y-axis
28-
frame=["WSne+tHistogram+glightgray", "x+lElevation (m)", "y+lCounts"],
27+
# Define the frame, add a title, and set the background color to "lightgray".
28+
# Add labels to the x-axis and y-axis
29+
frame=Frame(
30+
axes="WSne",
31+
title="Histogram",
32+
fill="lightgray",
33+
xaxis=Axis(label="Elevation (m)"),
34+
yaxis=Axis(label="Counts"),
35+
),
2936
# Generate evenly spaced bins by increments of 5
3037
series=5,
3138
# Use "red3" as color fill for the bars

examples/gallery/histograms/rose.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
# %%
1010
import pygmt
11+
from pygmt.params import Axis, Frame
1112

1213
# Load sample compilation of fracture lengths and azimuth as
1314
# hypothetically digitized from geological maps
@@ -34,11 +35,9 @@
3435
norm=True,
3536
# use red3 as color fill for the sectors
3637
fill="red3",
37-
# define the frame with ticks and gridlines every 0.2
38-
# length unit in radial direction and every 30 degrees
39-
# in azimuthal direction, set background color to
40-
# lightgray
41-
frame=["x0.2g0.2", "y30g30", "+glightgray"],
38+
# define the frame with gridlines every 0.2 length unit in radial direction
39+
# and every 30 degrees in azimuthal direction, set background color to lightgray
40+
frame=Frame(xaxis=Axis(grid=0.2), yaxis=Axis(grid=30), fill="lightgray"),
4241
# use a pen size of 1p to draw the outlines
4342
pen="1p",
4443
)

examples/gallery/images/contours.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
# %%
2424
import numpy as np
2525
import pygmt
26+
from pygmt.params import Axis
2627

2728
# Build the contours underlying data with the function z = x^2 + y^2
2829
X, Y = np.meshgrid(np.linspace(-10, 10, 50), np.linspace(-10, 10, 50))
@@ -34,7 +35,7 @@
3435
fig.contour(
3536
region=[-10, 10, -10, 10],
3637
projection="X10c/10c",
37-
frame="ag",
38+
frame=Axis(annot=True, grid=True),
3839
pen="0.5p",
3940
# Pass the data as 3 1-D data columns
4041
x=x,

examples/gallery/images/cross_section.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
# %%
1616
import pygmt
17-
from pygmt.params import Box, Position
17+
from pygmt.params import Axis, Box, Position
1818

1919
# Define region of study area
2020
# lon_min, lon_max, lat_min, lat_max in degrees East and North
@@ -30,7 +30,7 @@
3030
# Bottom: Map of elevation in study area
3131

3232
# Set up basic map using a Mercator projection with a width of 12 centimeters
33-
fig.basemap(region=region_map, projection="M12c", frame="af")
33+
fig.basemap(region=region_map, projection="M12c", frame=Axis(annot=True, tick=True))
3434

3535
# Download grid for Earth relief with a resolution of 10 arc-minutes and gridline
3636
# registration [Default]

examples/gallery/lines/line_segment_ends.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# %%
1212
import numpy as np
1313
import pygmt
14+
from pygmt.params import Frame
1415

1516
# Set up dictionary for colors
1617
dict_col = {
@@ -31,7 +32,7 @@
3132
x = np.array([30, 170])
3233
y = np.array([70, 70])
3334

34-
fig.basemap(region=[0, 260, 0, 100], projection="x1p", frame="rltb")
35+
fig.basemap(region=[0, 260, 0, 100], projection="x1p", frame=Frame(axes="rltb"))
3536

3637
for line_cap in ["butt", "round", "square"]:
3738
# Change GMT default locally
@@ -58,7 +59,7 @@
5859
x = np.array([5, 95, 65])
5960
y = np.array([10, 70, 10])
6061

61-
fig.basemap(region=[0, 260, 0, 100], projection="x1p", frame="rltb")
62+
fig.basemap(region=[0, 260, 0, 100], projection="x1p", frame=Frame(axes="rltb"))
6263

6364
for line_join in ["bevel", "round", "miter"]:
6465
with pygmt.config(PS_LINE_JOIN=line_join, PS_MITER_LIMIT=1):

examples/gallery/maps/borders.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,16 @@
1818

1919
# %%
2020
import pygmt
21+
from pygmt.params import Axis
2122

2223
fig = pygmt.Figure()
2324
# Make a Sinusoidal projection map of the Americas with automatic annotations,
2425
# ticks and gridlines
25-
fig.basemap(region=[-150, -30, -60, 60], projection="I-90/15c", frame="afg")
26+
fig.basemap(
27+
region=[-150, -30, -60, 60],
28+
projection="I-90/15c",
29+
frame=Axis(annot=True, tick=True, grid=True),
30+
)
2631
# Plot each level of the boundaries dataset with a different color.
2732
fig.coast(borders=["1/0.5p,black", "2/0.5p,red", "3/0.5p,blue"], land="gray")
2833
fig.show()

examples/gallery/maps/country_polygons.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
# %%
1414
import pygmt
15+
from pygmt.params import Axis
1516

1617
fig = pygmt.Figure()
1718

@@ -21,7 +22,7 @@
2122
projection="A10/52/25/6c",
2223
land="gray",
2324
water="white",
24-
frame="afg",
25+
frame=Axis(annot=True, tick=True, grid=True),
2526
dcw=[
2627
# Great Britain (country code) with seagreen land
2728
"GB+gseagreen",
@@ -54,7 +55,7 @@
5455
projection="H10c",
5556
land="gray",
5657
water="white",
57-
frame="afg",
58+
frame=Axis(annot=True, tick=True, grid=True),
5859
dcw=[
5960
# Europe
6061
"=EU+gseagreen",

0 commit comments

Comments
 (0)