|
| 1 | +""" |
| 2 | +Cartesian, circular, and geographic vectors |
| 3 | +------------------------------------------- |
| 4 | +
|
| 5 | +The :meth:`pygmt.Figure.plot` method can plot Cartesian, circular, and geographic vectors. |
| 6 | +The ``style`` parameter controls vector attributes. See also |
| 7 | +:doc:`Vector attributes documentation </gallery/line/vector-heads-tails>`. |
| 8 | +
|
| 9 | +""" |
| 10 | +import numpy as np |
| 11 | +import pygmt |
| 12 | + |
| 13 | +# create a plot with coast, Mercator projection (M) over the continental US |
| 14 | +fig = pygmt.Figure() |
| 15 | +fig.coast( |
| 16 | + region=[-127, -64, 24, 53], |
| 17 | + projection="M15c", |
| 18 | + frame=True, |
| 19 | + borders=1, |
| 20 | + area_thresh=4000, |
| 21 | + shorelines="0.25p,black", |
| 22 | +) |
| 23 | + |
| 24 | + |
| 25 | +# Left: plot 12 Cartesian vectors with different lengths |
| 26 | +x = np.linspace(-116, -116, 12) # x vector coordinates |
| 27 | +y = np.linspace(33.5, 42.5, 12) # y vector coordinates |
| 28 | +direction = np.zeros(x.shape) # direction of vectors |
| 29 | +length = np.linspace(0.5, 2.4, 12) # length of vectors |
| 30 | +# Cartesian vectors (v) with red pen and fill (+g, +p), vector head at end (+e), |
| 31 | +# and 40 degree angle (+a) with no indentation for vector head (+h) |
| 32 | +style = "v0.2c+e+a40+gred+h0+p1p,red" |
| 33 | +fig.plot(x=x, y=y, style=style, pen="1p,red", direction=[direction, length]) |
| 34 | +fig.text(text="CARTESIAN", x=-112, y=44.2, font="13p,Helvetica-Bold,red", fill="white") |
| 35 | + |
| 36 | + |
| 37 | +# Middle: plot 7 math angle arcs with different radii |
| 38 | +num = 7 |
| 39 | +x = np.full(num, -95) # x coordinates of the center |
| 40 | +y = np.full(num, 37) # y coordinates of the center |
| 41 | +radius = 1.8 - 0.2 * np.arange(0, num) # radius |
| 42 | +startdir = np.full(num, 90) # start direction in degrees |
| 43 | +stopdir = 180 + 40 * np.arange(0, num) # stop direction in degrees |
| 44 | +# data for circular vectors |
| 45 | +data = np.column_stack([x, y, radius, startdir, stopdir]) |
| 46 | +arcstyle = "m0.5c+ea" # Circular vector (m) with an arrow at end |
| 47 | +fig.plot(data=data, style=arcstyle, color="red3", pen="1.5p,black") |
| 48 | +fig.text(text="CIRCULAR", x=-95, y=44.2, font="13p,Helvetica-Bold,black", fill="white") |
| 49 | + |
| 50 | + |
| 51 | +# Right: plot geographic vectors using endpoints |
| 52 | +NYC = [-74.0060, 40.7128] |
| 53 | +CHI = [-87.6298, 41.8781] |
| 54 | +SEA = [-122.3321, 47.6062] |
| 55 | +NO = [-90.0715, 29.9511] |
| 56 | +# `=` means geographic vectors. |
| 57 | +# With the modifier '+s', the input data should contain coordinates of start and end points |
| 58 | +style = "=0.5c+s+e+a30+gblue+h0.5+p1p,blue" |
| 59 | +data = np.array([NYC + CHI, NYC + SEA, NYC + NO]) |
| 60 | +fig.plot(data=data, style=style, pen="1.0p,blue") |
| 61 | +fig.text( |
| 62 | + text="GEOGRAPHIC", x=-74.5, y=44.2, font="13p,Helvetica-Bold,blue", fill="white" |
| 63 | +) |
| 64 | +fig.show() |
0 commit comments