Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a gallery example showing different vector heads and tails #890

Merged
merged 31 commits into from
Feb 20, 2021
Merged
Changes from 30 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
525b1f9
Create vectors.py
michaelgrund Feb 14, 2021
8479e60
formatting etc.
michaelgrund Feb 14, 2021
7342953
adjustments
michaelgrund Feb 14, 2021
df29128
Merge branch 'master' into michaelgrund-example-vectors
michaelgrund Feb 14, 2021
fbc2866
modified docs
michaelgrund Feb 14, 2021
153a92d
Merge branch 'michaelgrund-example-vectors' of https://github.com/Gen…
michaelgrund Feb 14, 2021
07820ee
corrected typos
michaelgrund Feb 14, 2021
7b468df
added example showing different vector heads and tails
michaelgrund Feb 16, 2021
0702083
Merge branch 'master' into michaelgrund-example-vectors
michaelgrund Feb 16, 2021
b44f1b0
formatting
michaelgrund Feb 16, 2021
6341270
corrected typo
michaelgrund Feb 16, 2021
df61c9c
Merge branch 'master' into michaelgrund-example-vectors
michaelgrund Feb 16, 2021
5aaac63
Update examples/gallery/line/vector-heads-tails.py
michaelgrund Feb 17, 2021
510e25d
Merge branch 'master' into michaelgrund-example-vectors
michaelgrund Feb 17, 2021
46f59d5
modifications based on review
michaelgrund Feb 17, 2021
c07ffb7
added Meghans suggestion
michaelgrund Feb 17, 2021
4e56a16
Merge branch 'master' into michaelgrund-example-vectors
michaelgrund Feb 18, 2021
7d38f41
some formatting
michaelgrund Feb 18, 2021
65520a6
formatting theta
michaelgrund Feb 18, 2021
a2f0ede
formatting theta
michaelgrund Feb 18, 2021
c759181
removed theta
michaelgrund Feb 18, 2021
3252005
Update examples/gallery/line/vector-heads-tails.py
michaelgrund Feb 18, 2021
b6d065c
Update examples/gallery/line/vector-heads-tails.py
michaelgrund Feb 18, 2021
4242351
Merge branch 'master' into michaelgrund-example-vectors
michaelgrund Feb 18, 2021
0cb0438
Update examples/gallery/line/vector-heads-tails.py
michaelgrund Feb 19, 2021
77bc3be
Merge branch 'master' into michaelgrund-example-vectors
michaelgrund Feb 19, 2021
c4d4ad9
updates based on review
michaelgrund Feb 19, 2021
3877278
Update examples/gallery/line/vector-heads-tails.py
michaelgrund Feb 19, 2021
e8bdc83
Update examples/gallery/line/vector-heads-tails.py
michaelgrund Feb 19, 2021
847b408
removed trailing white spaces
michaelgrund Feb 19, 2021
0b4d158
Merge branch 'master' into michaelgrund-example-vectors
seisman Feb 20, 2021
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
81 changes: 81 additions & 0 deletions examples/gallery/line/vector-heads-tails.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
"""
Vector heads and tails
----------------------

Many modules in PyGMT allow plotting vectors with individual
heads and tails. For this purpose, several modifiers may be appended to
the corresponding vector-producing parameters for specifying the placement
of vector heads and tails, their shapes, and the justification of the vector.

To place a vector head at the beginning of the vector path
simply append **+b** to the vector-producing option (use **+e** to place
one at the end). Optionally, append **t** for a terminal line, **c** for a
circle, **a** for arrow (default), **i** for tail, **A** for plain open
arrow, and **I** for plain open tail. Further append **l** or **r** (e.g.
``+bar``) to only draw the left or right half-sides of the selected head/tail
(default is both sides) or use **+l** or **+r** to apply simultaneously to both
sides. In this context left and right refer to the side of the vector line
when viewed from the beginning point to the end point of a line segment.
The angle of the vector head apex can be set using **+a**\ *angle*
(default is 30). The shape of the vector head can be adjusted using
**+h**\ *shape* (e.g. ``+h0.5``).

For further modifiers see the *Vector Attributes* subsection of the
corresponding module.

In the following we use the :meth:`pygmt.Figure.plot` method to plot vectors
with individual heads and tails. We must specify the modifiers (together with
the vector type, here ``v``) by passing the corresponding shortcuts to the
``style`` parameter.

"""

import pygmt

fig = pygmt.Figure()
fig.basemap(
region=[0, 10, 0, 15], projection="X15c/10c", frame='+t"Vector heads and tails"'
)

x = 1
y = 14
angle = 0 # in degrees, measured counter-clockwise from horizontal
length = 7

for vecstyle in [
# vector without head and tail (line)
"v0c",
# plain open arrow at beginning and end, angle of the vector head apex is set to 50
"v0.6c+bA+eA+a50",
# plain open tail at beginning and end
"v0.4c+bI+eI",
# terminal line at beginning and end, angle of vector head apex is set to 80
"v0.3c+bt+et+a80",
# arrow head at end
"v0.6c+e",
# circle at beginning and arrow head at end
"v0.6c+bc+ea",
# terminal line at beginning and arrow head at end
"v0.6c+bt+ea",
# arrow head at end, shape of vector head is set to 0.5
"v1c+e+h0.5",
# modified arrow heads at beginning and end
"v1c+b+e+h0.5",
# tail at beginning and arrow with modified vector head at end
"v1c+bi+ea+h0.5",
# half-sided arrow head (right side) at beginning and arrow at the end
"v1c+bar+ea+h0.8",
# half-sided arrow heads at beginning (right side) and end (left side)
"v1c+bar+eal+h0.5",
# half-sided tail at beginning and arrow at end (right side for both)
"v1c+bi+ea+r+h0.5+a45",
]:
fig.plot(
x=x, y=y, style=vecstyle, direction=([angle], [length]), pen="2p", color="red3"
)
fig.text(
x=6, y=y, text=vecstyle, font="Courier-Bold", justify="ML", offset="0.2c/0c"
)
y -= 1 # move the next vector down

fig.show()