Skip to content

Commit 9a63274

Browse files
michaelgrundseismanMeghan Jones
authored
Add a gallery example showing different vector heads and tails (#890)
Co-authored-by: Dongdong Tian <[email protected]> Co-authored-by: Meghan Jones <[email protected]>
1 parent 5a4731f commit 9a63274

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
"""
2+
Vector heads and tails
3+
----------------------
4+
5+
Many modules in PyGMT allow plotting vectors with individual
6+
heads and tails. For this purpose, several modifiers may be appended to
7+
the corresponding vector-producing parameters for specifying the placement
8+
of vector heads and tails, their shapes, and the justification of the vector.
9+
10+
To place a vector head at the beginning of the vector path
11+
simply append **+b** to the vector-producing option (use **+e** to place
12+
one at the end). Optionally, append **t** for a terminal line, **c** for a
13+
circle, **a** for arrow (default), **i** for tail, **A** for plain open
14+
arrow, and **I** for plain open tail. Further append **l** or **r** (e.g.
15+
``+bar``) to only draw the left or right half-sides of the selected head/tail
16+
(default is both sides) or use **+l** or **+r** to apply simultaneously to both
17+
sides. In this context left and right refer to the side of the vector line
18+
when viewed from the beginning point to the end point of a line segment.
19+
The angle of the vector head apex can be set using **+a**\ *angle*
20+
(default is 30). The shape of the vector head can be adjusted using
21+
**+h**\ *shape* (e.g. ``+h0.5``).
22+
23+
For further modifiers see the *Vector Attributes* subsection of the
24+
corresponding module.
25+
26+
In the following we use the :meth:`pygmt.Figure.plot` method to plot vectors
27+
with individual heads and tails. We must specify the modifiers (together with
28+
the vector type, here ``v``) by passing the corresponding shortcuts to the
29+
``style`` parameter.
30+
31+
"""
32+
33+
import pygmt
34+
35+
fig = pygmt.Figure()
36+
fig.basemap(
37+
region=[0, 10, 0, 15], projection="X15c/10c", frame='+t"Vector heads and tails"'
38+
)
39+
40+
x = 1
41+
y = 14
42+
angle = 0 # in degrees, measured counter-clockwise from horizontal
43+
length = 7
44+
45+
for vecstyle in [
46+
# vector without head and tail (line)
47+
"v0c",
48+
# plain open arrow at beginning and end, angle of the vector head apex is set to 50
49+
"v0.6c+bA+eA+a50",
50+
# plain open tail at beginning and end
51+
"v0.4c+bI+eI",
52+
# terminal line at beginning and end, angle of vector head apex is set to 80
53+
"v0.3c+bt+et+a80",
54+
# arrow head at end
55+
"v0.6c+e",
56+
# circle at beginning and arrow head at end
57+
"v0.6c+bc+ea",
58+
# terminal line at beginning and arrow head at end
59+
"v0.6c+bt+ea",
60+
# arrow head at end, shape of vector head is set to 0.5
61+
"v1c+e+h0.5",
62+
# modified arrow heads at beginning and end
63+
"v1c+b+e+h0.5",
64+
# tail at beginning and arrow with modified vector head at end
65+
"v1c+bi+ea+h0.5",
66+
# half-sided arrow head (right side) at beginning and arrow at the end
67+
"v1c+bar+ea+h0.8",
68+
# half-sided arrow heads at beginning (right side) and end (left side)
69+
"v1c+bar+eal+h0.5",
70+
# half-sided tail at beginning and arrow at end (right side for both)
71+
"v1c+bi+ea+r+h0.5+a45",
72+
]:
73+
fig.plot(
74+
x=x, y=y, style=vecstyle, direction=([angle], [length]), pen="2p", color="red3"
75+
)
76+
fig.text(
77+
x=6, y=y, text=vecstyle, font="Courier-Bold", justify="ML", offset="0.2c/0c"
78+
)
79+
y -= 1 # move the next vector down
80+
81+
fig.show()

0 commit comments

Comments
 (0)