Skip to content

Commit f57943f

Browse files
michaelgrundseismanMeghan Jones
authored
Add gallery example showing different polar projection use cases (#955)
Co-authored-by: Dongdong Tian <[email protected]> Co-authored-by: Meghan Jones <[email protected]>
1 parent ce5cd2f commit f57943f

File tree

1 file changed

+148
-12
lines changed

1 file changed

+148
-12
lines changed

examples/projections/nongeo/polar.py

+148-12
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,158 @@
1-
"""
1+
r"""
22
Polar
33
=====
44
5-
**P**\ *width*: Give the *width* of the figure.
5+
Polar projections allow plotting polar coordinate data (e.g. angle
6+
:math:`\theta` and radius *r*).
7+
8+
The full syntax for polar projections is:
9+
10+
**P**\ *width*\ [**+a**]\ [**+f**\ [**e**\|\ **p**\|\ *radius*]]\
11+
[**+r**\ *offset*][**+t**\ *origin*][**+z**\ [**p**\|\ *radius*]]
12+
13+
Limits are set via the ``region`` parameter
14+
([*theta_min*, *theta_max*, *radius_min*, *radius_max*]). When using
15+
**P**\ *width* you have to give the *width* of the figure. The lower-case
16+
version **p** is similar to **P** but expects a *scale* instead of
17+
a width (**p**\ *scale*).
18+
19+
The following customizing modifiers are available:
20+
21+
- **+a**: by default, :math:`\theta` refers to the angle that is equivalent to
22+
a counterclockwise rotation with respect to the east direction (standard
23+
definition); **+a** indicates that the input data is rotated clockwise
24+
relative to the north direction (geographical azimuth angle).
25+
26+
- **+r**\ *offset*: represents the offset of the r axis. This modifier allows
27+
you to offset the center of the circle from r=0.
28+
29+
- **+t**\ *origin*: sets the angle corresponding to the east direction which is
30+
equivalent to rotating the entire coordinate axis clockwise; if the **+a**
31+
modifier is used, setting the angle corresponding to the north direction is
32+
equivalent to rotating the entire coordinate axis counterclockwise.
33+
34+
- **+f**: reverses the radial direction.
35+
36+
- Append **e** to indicate that the r-axis is an elevation angle, and the
37+
range of the r-axis should be between 0 and 90.
38+
- Appending **p** sets the current earth radius (determined by
39+
:gmt-term:`PROJ_ELLIPSOID`)
40+
to the maximum value of the r axis when the r axis is reversed.
41+
- Append *radius* to set the maximum value of the r axis.
42+
43+
- **+z**: indicates that the r axis is marked as depth instead of radius (e.g.
44+
*r = radius - z*).
45+
46+
- Append **p** to set radius to the current earth radius.
47+
- Append *radius* to set the value of the radius.
648
749
"""
50+
851
import pygmt
952

1053
fig = pygmt.Figure()
11-
fig.plot(
12-
# x inputs are the theta values for a polar plot.
13-
x=[180, 120, 270, 60, 0],
14-
# y inputs are the radius values for a polar plot.
15-
y=[15, 35, 15, 35, 15],
16-
pen="2p,blue",
17-
# The region values are theta-min/theta-max/radius-min/radius-max.
18-
region=[0, 360, 0, 40],
19-
projection="P15c",
20-
frame=["afg"],
54+
55+
pygmt.config(FONT_TITLE="14p,Helvetica,black", FORMAT_GEO_MAP="+D")
56+
57+
# ============
58+
59+
fig.basemap(
60+
# set map limits to theta_min = 0, theta_max = 360, radius_min = 0, radius_max = 1
61+
region=[0, 360, 0, 1],
62+
# set map width to 5 cm
63+
projection="P5c",
64+
# set the frame and color
65+
frame=["xa45f", "+gbisque"],
66+
)
67+
68+
fig.text(position="TC", text="projection='P5c'", offset="0/2.0c", no_clip=True)
69+
fig.text(position="TC", text="region=[0, 360, 0, 1]", offset="0/1.5c", no_clip=True)
70+
71+
fig.shift_origin(xshift="8c")
72+
73+
# ============
74+
fig.basemap(
75+
# set map limits to theta_min = 0, theta_max = 360, radius_min = 0, radius_max = 1
76+
region=[0, 360, 0, 1],
77+
# set map width to 5 cm and interpret input data as geographic azimuth instead
78+
# of standard angle
79+
projection="P5c+a",
80+
# set the frame and color
81+
frame=["xa45f", "+gbisque"],
2182
)
83+
84+
fig.text(position="TC", text="projection='P5c+a'", offset="0/2.0c", no_clip=True)
85+
fig.text(position="TC", text="region=[0, 360, 0, 1]", offset="0/1.5c", no_clip=True)
86+
87+
fig.shift_origin(xshift="8c")
88+
89+
# ============
90+
fig.basemap(
91+
# set map limits to theta_min = 0, theta_max = 90, radius_min = 0, radius_max = 1
92+
region=[0, 90, 0, 1],
93+
# set map width to 5 cm and interpret input data as geographic azimuth instead
94+
# of standard angle
95+
projection="P5c+a",
96+
# set the frame and color
97+
frame=["xa45f", "ya0.2", "WNe+gbisque"],
98+
)
99+
100+
fig.text(position="TC", text="projection='P5c+a'", offset="0/2.0c", no_clip=True)
101+
fig.text(position="TC", text="region=[0, 90, 0, 1]", offset="0/1.5c", no_clip=True)
102+
103+
fig.shift_origin(xshift="-16c", yshift="-7c")
104+
105+
# ============
106+
fig.basemap(
107+
# set map limits to theta_min = 0, theta_max = 90, radius_min = 0, radius_max = 1
108+
region=[0, 90, 0, 1],
109+
# set map width to 5 cm and interpret input data as geographic azimuth instead
110+
# of standard angle, rotate coordinate system counterclockwise by 45 degrees
111+
projection="P5c+a+t45",
112+
# set the frame and color
113+
frame=["xa30f", "ya0.2", "WNe+gbisque"],
114+
)
115+
116+
fig.text(position="TC", text="projection='P5c+a\+t45'", offset="0/2.0c", no_clip=True)
117+
fig.text(position="TC", text="region=[0, 90, 0, 1]", offset="0/1.5c", no_clip=True)
118+
119+
fig.shift_origin(xshift="8c", yshift="1.3c")
120+
121+
# ============
122+
fig.basemap(
123+
# set map limits to theta_min = 0, theta_max = 90, radius_min = 3480,
124+
# radius_max = 6371 (Earth's radius)
125+
region=[0, 90, 3480, 6371],
126+
# set map width to 5 cm and interpret input data as geographic azimuth instead
127+
# of standard angle, rotate coordinate system counterclockwise by 45 degrees
128+
projection="P5c+a+t45",
129+
# set the frame and color
130+
frame=["xa30f", "ya", "WNse+gbisque"],
131+
)
132+
133+
fig.text(position="TC", text="projection='P5c+a\+t45'", offset="0/2.0c", no_clip=True)
134+
fig.text(
135+
position="TC", text="region=[0, 90, 3480, 6371]", offset="0/1.5c", no_clip=True
136+
)
137+
138+
fig.shift_origin(xshift="8c")
139+
140+
# ============
141+
fig.basemap(
142+
# set map limits to theta_min = 0, theta_max = 90, radius_min = 3480,
143+
# radius_max = 6371 (Earth's radius)
144+
region=[0, 90, 3480, 6371],
145+
# set map width to 5 cm and interpret input data as geographic azimuth instead
146+
# of standard angle, rotate coordinate system counterclockwise by 45 degrees,
147+
# r axis is marked as depth
148+
projection="P5c+a+t45+z",
149+
# set the frame and color
150+
frame=["xa30f", "ya", "WNse+gbisque"],
151+
)
152+
153+
fig.text(position="TC", text="projection='P5c+a\+t45+z'", offset="0/2.0c", no_clip=True)
154+
fig.text(
155+
position="TC", text="region=[0, 90, 3480, 6371]", offset="0/1.5c", no_clip=True
156+
)
157+
22158
fig.show()

0 commit comments

Comments
 (0)