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 for plotting Cartesian, circular and geographic vectors #950

Merged
merged 24 commits into from
Mar 2, 2021
Merged
Changes from 15 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
cef2a2d
gallery figure for plot -Sv with vectors
kmaterna Feb 22, 2021
72e17c0
geo/cartesian/circ gallery example
kmaterna Feb 23, 2021
2b8c406
[format-command] fixes
actions-bot Feb 23, 2021
2ede9ab
editorial changes to vector example
kmaterna Feb 23, 2021
93a138e
[format-command] fixes
actions-bot Feb 23, 2021
2f1440f
simplifying changes
kmaterna Feb 24, 2021
0b905d7
np array construction for vector example
kmaterna Feb 25, 2021
9a5e866
[format-command] fixes
actions-bot Feb 25, 2021
bb7ac0e
Update examples/gallery/plot/vectors.py comments
kmaterna Feb 26, 2021
c6c5e71
Update examples/gallery/plot/vectors.py remove for loop
kmaterna Feb 26, 2021
d4d8e84
Update examples/gallery/plot/vectors.py
kmaterna Feb 26, 2021
1b09288
moving vectors to line gallery
kmaterna Feb 26, 2021
56e8436
Merge branch 'master' into gallery_vectors
seisman Feb 26, 2021
3115efa
[format-command] fixes
actions-bot Feb 26, 2021
e4a09b6
Merge branch 'master' into gallery_vectors
seisman Feb 26, 2021
0b22dee
Update examples/gallery/line/vectors.py line reorder
kmaterna Feb 26, 2021
6a22200
Update examples/gallery/line/vectors.py comment added
kmaterna Feb 26, 2021
7fc33a2
Update examples/gallery/line/vectors.py
kmaterna Feb 28, 2021
70698d2
Update examples/gallery/line/vectors.py
kmaterna Feb 28, 2021
ab484e0
Update examples/gallery/line/vectors.py
kmaterna Feb 28, 2021
5bdb296
documentation improvements for vector heads
kmaterna Mar 1, 2021
1efe495
[format-command] fixes
actions-bot Mar 1, 2021
220f4f9
Update examples/gallery/line/vectors.py
kmaterna Mar 2, 2021
a5311a5
Update vectors.py doc linking functions
kmaterna Mar 2, 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
63 changes: 63 additions & 0 deletions examples/gallery/line/vectors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""
Cartesian, circular, and geographic vectors
-------------------------------------------

The :meth:`pygmt.Figure.plot` method can plot Cartesian, circular, and geographic vectors.
The ``style`` parameter controls vector attributes.
kmaterna marked this conversation as resolved.
Show resolved Hide resolved

"""
import numpy as np
import pygmt

# create a plot with coast, Mercator projection (M) over the continental US
fig = pygmt.Figure()
fig.coast(
region=[-127, -64, 24, 53],
projection="M15c",
frame=True,
borders=1,
area_thresh=4000,
shorelines="0.25p,black",
)


# plot 12 Cartesian vectors with different lengths
kmaterna marked this conversation as resolved.
Show resolved Hide resolved
x = np.linspace(-116, -116, 12) # x vector coordinates
y = np.linspace(33.5, 42.5, 12) # y vector coordinates
direction = np.zeros(x.shape) # direction of vectors
length = np.linspace(0.5, 2.4, 12) # length of vectors
# vectors with red pen and fill, vector head at end, and 40 degree angle for vector head
kmaterna marked this conversation as resolved.
Show resolved Hide resolved
style = "v0.2c+e+a40+gred+h0+p1p,red"
fig.plot(x=x, y=y, style=style, pen="1p,red", direction=[direction, length])
fig.text(text="CARTESIAN", x=-112, y=44.2, font="13p,Helvetica-Bold,red", fill="white")


# plot 7 math angle arcs with different radii
kmaterna marked this conversation as resolved.
Show resolved Hide resolved
num = 7
x = np.full(num, -95) # x coordinates of the center
y = np.full(num, 37) # y coordinates of the center
radius = 1.8 - 0.2 * np.arange(0, num) # radius
startdir = np.full(num, 90) # start direction in degrees
stopdir = 180 + 40 * np.arange(0, num) # stop direction in degrees
arcstyle = "m0.5c+ea" # vector with an arrow at end

# data for circular vectors
data = np.column_stack([x, y, radius, startdir, stopdir])
kmaterna marked this conversation as resolved.
Show resolved Hide resolved
fig.plot(data=data, style=arcstyle, color="red3", pen="1.5p,black")
fig.text(text="CIRCULAR", x=-95, y=44.2, font="13p,Helvetica-Bold,black", fill="white")


# plot geographic vectors using endpoints
kmaterna marked this conversation as resolved.
Show resolved Hide resolved
NYC = [-74.0060, 40.7128]
CHI = [-87.6298, 41.8781]
SEA = [-122.3321, 47.6062]
NO = [-90.0715, 29.9511]
# `=` means geographic vectors.
# With the modifier '+s', the input data should contain coordinates of start and end points
style = "=0.5c+s+e+a30+gblue+h0.5+p1p,blue"
data = np.array([NYC + CHI, NYC + SEA, NYC + NO])
fig.plot(data=data, style=style, pen="1.0p,blue")
fig.text(
text="GEOGRAPHIC", x=-74.5, y=44.2, font="13p,Helvetica-Bold,blue", fill="white"
)
fig.show()