Skip to content

Commit 7f37e1c

Browse files
core-manweiji14michaelgrundseismanMeghan Jones
authored
Specify rectangle's width and height via style parameter in multi-parameter symbols example (#1325)
* Update rectangle in the multi-parameter symbols * Apply suggestions from code review Co-authored-by: Wei Ji <[email protected]> * Apply suggestions from code review Co-authored-by: Wei Ji <[email protected]> * Add new syntax for all the multi-parameter symbols * Split the example into two figures * Update comments * Add gallery thumbnail number * Update sytle * Apply suggestions from code review Co-authored-by: Meghan Jones <[email protected]> Co-authored-by: Wei Ji <[email protected]> Co-authored-by: Michael Grund <[email protected]> Co-authored-by: Dongdong Tian <[email protected]> Co-authored-by: Meghan Jones <[email protected]>
1 parent c126a33 commit 7f37e1c

File tree

1 file changed

+70
-31
lines changed

1 file changed

+70
-31
lines changed

examples/gallery/symbols/multi_parameter_symbols.py

Lines changed: 70 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,87 @@
33
-------------------------
44
55
The :meth:`pygmt.Figure.plot` method can plot individual multi-parameter
6-
symbols by passing the corresponding shortcuts listed below to the ``style``
7-
parameter. Additionally, we must define the required parameters in a 2d list or
8-
numpy array (``[[parameters]]`` for a single symbol or
9-
``[[parameters_1],[parameters_2],[parameters_i]]`` for several ones) or use an
10-
appropriately formatted input file and pass it to ``data``.
11-
12-
The following symbols are available:
13-
14-
- **e**: ellipse, ``[[lon, lat, direction, major_axis, minor_axis]]``
15-
- **j**: rotated rectangle, ``[[lon, lat, direction, width, height]]``
16-
- **r**: rectangle, ``[[lon, lat, width, height]]``
17-
- **R**: rounded rectangle, ``[[lon, lat, width, height, radius]]``
18-
- **w**: pie wedge, ``[[lon, lat, radius, startdir, stopdir]]``, the last two
19-
arguments are directions given in degrees counter-clockwise from horizontal
20-
21-
Upper-case versions **E**, **J**, and **W** are similar to **e**, **j** and
22-
**w** but expect geographic azimuths and distances.
6+
symbols by passing the corresponding shortcuts (**e**, **j**, **r**, **R**,
7+
**w**) to the ``style`` parameter:
8+
9+
- **e**: ellipse
10+
- **j**: rotated rectangle
11+
- **r**: rectangle
12+
- **R**: rounded rectangle
13+
- **w**: pie wedge
14+
2315
"""
2416

17+
# sphinx_gallery_thumbnail_number = 2
18+
2519
import pygmt
2620

21+
########################################################################################
22+
# We can plot multi-parameter symbols using the same symbol style. We need to
23+
# define locations (lon, lat) via the ``x`` and ``y`` parameters (scalar for
24+
# a single symbol or 1d list for several ones) and two or three symbol
25+
# parameters after those shortcuts via the ``style`` parameter.
26+
#
27+
# The multi-parameter symbols in the ``style`` parameter are defined as:
28+
#
29+
# - **e**: ellipse, ``direction/major_axis/minor_axis``
30+
# - **j**: rotated rectangle, ``direction/width/height``
31+
# - **r**: rectangle, ``width/height``
32+
# - **R**: rounded rectangle, ``width/height/radius``
33+
# - **w**: pie wedge, ``radius/startdir/stopdir``, the last two arguments are
34+
# directions given in degrees counter-clockwise from horizontal
35+
#
36+
# Upper-case versions **E**, **J**, and **W** are similar to **e**, **j** and
37+
# **w** but expect geographic azimuths and distances.
38+
2739
fig = pygmt.Figure()
2840
fig.basemap(region=[0, 6, 0, 2], projection="x3c", frame=True)
2941

30-
# ELLIPSE
31-
data = [[0.5, 1, 45, 3, 1]]
32-
fig.plot(data=data, style="e", color="orange", pen="2p,black")
42+
# Ellipse
43+
fig.plot(x=0.5, y=1, style="e45/3/1", color="orange", pen="2p,black")
44+
# Rotated rectangle
45+
fig.plot(x=1.5, y=1, style="j120/5/0.5", color="red3", pen="2p,black")
46+
# Rectangle
47+
fig.plot(x=3, y=1, style="r4/1.5", color="dodgerblue", pen="2p,black")
48+
# Rounded rectangle
49+
fig.plot(x=4.5, y=1, style="R1.25/4/0.5", color="seagreen", pen="2p,black")
50+
# Pie wedge
51+
fig.plot(x=5.5, y=1, style="w2.5/45/330", color="lightgray", pen="2p,black")
3352

34-
# ROTATED RECTANGLE
35-
data = [[1.5, 1, 120, 5, 0.5]]
36-
fig.plot(data=data, style="j", color="red3", pen="2p,black")
53+
fig.show()
3754

38-
# RECTANGLE
39-
data = [[3, 1, 4, 1.5]]
40-
fig.plot(data=data, style="r", color="dodgerblue", pen="2p,black")
55+
########################################################################################
56+
# We can also plot symbols with varying parameters via defining those values in
57+
# a 2d list or numpy array (``[[parameters]]`` for a single symbol or
58+
# ``[[parameters_1],[parameters_2],[parameters_i]]`` for several ones) or using
59+
# an appropriately formatted input file and passing it to ``data``.
60+
#
61+
# The symbol parameters in the 2d list or numpy array are defined as:
62+
#
63+
# - **e**: ellipse, ``[[lon, lat, direction, major_axis, minor_axis]]``
64+
# - **j**: rotated rectangle, ``[[lon, lat, direction, width, height]]``
65+
# - **r**: rectangle, ``[[lon, lat, width, height]]``
66+
# - **R**: rounded rectangle, ``[[lon, lat, width, height, radius]]``
67+
# - **w**: pie wedge, ``[[lon, lat, radius, startdir, stopdir]]``, the last two
68+
# arguments are directions given in degrees counter-clockwise from horizontal
4169

42-
# ROUNDED RECTANGLE
43-
data = [[4.5, 1, 1.25, 4, 0.5]]
44-
fig.plot(data=data, style="R", color="seagreen", pen="2p,black")
70+
fig = pygmt.Figure()
71+
fig.basemap(region=[0, 6, 0, 4], projection="x3c", frame=["xa1f0.2", "ya0.5f0.1"])
4572

46-
# PIE WEDGE
47-
data = [[5.5, 1, 2.5, 45, 330]]
73+
# Ellipse
74+
data = [[0.5, 1, 45, 3, 1], [0.5, 3, 135, 2, 1]]
75+
fig.plot(data=data, style="e", color="orange", pen="2p,black")
76+
# Rotated rectangle
77+
data = [[1.5, 1, 120, 5, 0.5], [1.5, 3, 50, 3, 0.5]]
78+
fig.plot(data=data, style="j", color="red3", pen="2p,black")
79+
# Rectangle
80+
data = [[3, 1, 4, 1.5], [3, 3, 3, 1.5]]
81+
fig.plot(data=data, style="r", color="dodgerblue", pen="2p,black")
82+
# Rounded rectangle
83+
data = [[4.5, 1, 1.25, 4, 0.5], [4.5, 3, 1.25, 2.0, 0.2]]
84+
fig.plot(data=data, style="R", color="seagreen", pen="2p,black")
85+
# Pie wedge
86+
data = [[5.5, 1, 2.5, 45, 330], [5.5, 3, 1.5, 60, 300]]
4887
fig.plot(data=data, style="w", color="lightgray", pen="2p,black")
4988

5089
fig.show()

0 commit comments

Comments
 (0)