|
1 | 1 | """
|
2 |
| -Plotting Datetime Charts |
3 |
| -======================== |
| 2 | +Plotting Date Time Charts |
| 3 | +================ |
4 | 4 |
|
5 |
| -Plotting datetime charts is handled by :meth:`pygmt.Figure.basemap`. |
| 5 | +Plotting vectors is handled by :meth:`pygmt.Figure.basemap`. |
6 | 6 |
|
7 | 7 | .. note::
|
8 | 8 |
|
|
13 | 13 | To save the figure, use ``fig.savefig("figname.pdf")`` where ``"figname.pdf"``
|
14 | 14 | is the desired name and file extension for the saved figure.
|
15 | 15 | """
|
16 |
| -# sphinx_gallery_thumbnail_number = 0 |
| 16 | +# sphinx_gallery_thumbnail_number = 6 |
17 | 17 |
|
18 | 18 | import numpy as np
|
19 | 19 | import pygmt
|
20 | 20 |
|
21 |
| -######################################################################################## |
| 21 | +######################################################################################### |
22 | 22 | # Plot Cartesian Vectors
|
23 | 23 | # ----------------------
|
24 | 24 | #
|
|
51 | 51 | direction=[[-45], [6]],
|
52 | 52 | )
|
53 | 53 | fig.show()
|
54 |
| - |
55 |
| -######################################################################################## |
56 |
| -# In this example, we apply the same concept shown previously to plot multiple |
57 |
| -# vectors. Notice that instead of passing int/float to ``x`` and ``y``, a list |
58 |
| -# of all x and y coordinates will be passed. Similarly, the length of direction |
59 |
| -# list will increase accordingly. |
60 |
| -# |
61 |
| -# Additionally, we change the style of the vector to include a red |
62 |
| -# arrow head at the end (**+e**) of the vector and increase the |
63 |
| -# thickness (``pen="2p"``) of the vector stem. A list of different |
64 |
| -# styling attributes can be found in |
65 |
| -# :doc:`Vector heads and tails </gallery/lines/vector_heads_tails>`. |
66 |
| - |
67 |
| -fig = pygmt.Figure() |
68 |
| -fig.plot( |
69 |
| - region=[0, 10, 0, 10], |
70 |
| - projection="X10c/10c", |
71 |
| - frame="ag", |
72 |
| - x=[2, 4], |
73 |
| - y=[8, 1], |
74 |
| - style="v0.6c+e", |
75 |
| - direction=[[-45, 23], [6, 3]], |
76 |
| - pen="2p", |
77 |
| - color="red3", |
78 |
| -) |
79 |
| -fig.show() |
80 |
| - |
81 |
| -######################################################################################## |
82 |
| -# The default unit of vector length is centimeters, |
83 |
| -# however, this can be changed to inches or points. Note that, in PyGMT, |
84 |
| -# one point is defined as 1/72 inch. |
85 |
| -# |
86 |
| -# In this example, the graphed region is 5in X 5in, but |
87 |
| -# the length of the first vector is still graphed in centimeters. |
88 |
| -# Using ``pygmt.config(PROJ_LENGTH_UNIT="i")``, the default unit |
89 |
| -# can be changed to inches in the second plotted vector. |
90 |
| - |
91 |
| -fig = pygmt.Figure() |
92 |
| -# Vector 1 with default unit as cm |
93 |
| -fig.plot( |
94 |
| - region=[0, 10, 0, 10], |
95 |
| - projection="X5i/5i", |
96 |
| - frame="ag", |
97 |
| - x=2, |
98 |
| - y=8, |
99 |
| - style="v1c+e", |
100 |
| - direction=[[0], [3]], |
101 |
| - pen="2p", |
102 |
| - color="red3", |
103 |
| -) |
104 |
| -# Vector 2 after changing default unit to inch |
105 |
| -with pygmt.config(PROJ_LENGTH_UNIT="i"): |
106 |
| - fig.plot( |
107 |
| - x=2, |
108 |
| - y=7, |
109 |
| - direction=[[0], [3]], |
110 |
| - style="v1c+e", |
111 |
| - pen="2p", |
112 |
| - color="red3", |
113 |
| - ) |
114 |
| -fig.show() |
115 |
| - |
116 |
| -######################################################################################## |
117 |
| -# Vectors can also be plotted by including all the information |
118 |
| -# about a vector in a single list. However, this requires creating |
119 |
| -# a 2D list or numpy array containing all vectors. |
120 |
| -# Each vector list contains the information structured as: |
121 |
| -# ``[x_start, y_start, direction_degrees, length]``. |
122 |
| -# |
123 |
| -# If this approach is chosen, the ``data`` parameter must be |
124 |
| -# used instead of ``x``, ``y`` and ``direction``. |
125 |
| - |
126 |
| -# Create a list of lists that include each vector information |
127 |
| -vectors = [[2, 3, 45, 4]] |
128 |
| - |
129 |
| -fig = pygmt.Figure() |
130 |
| -fig.plot( |
131 |
| - region=[0, 10, 0, 10], |
132 |
| - projection="X10c/10c", |
133 |
| - frame="ag", |
134 |
| - data=vectors, |
135 |
| - style="v0.6c+e", |
136 |
| - pen="2p", |
137 |
| - color="red3", |
138 |
| -) |
139 |
| -fig.show() |
140 |
| - |
141 |
| -######################################################################################## |
142 |
| -# Using the functionality mentioned in the previous example, |
143 |
| -# multiple vectors can be plotted at the same time. Another |
144 |
| -# vector could be simply added to the 2D list or numpy |
145 |
| -# array object and passed using ``data`` parameter. |
146 |
| - |
147 |
| -# Vector specifications structured as: [x_start, y_start, direction_degrees, length] |
148 |
| -vector_1 = [2, 3, 45, 4] |
149 |
| -vector_2 = [7.5, 8.3, -120.5, 7.2] |
150 |
| -# Create a list of lists that include each vector information |
151 |
| -vectors = [vector_1, vector_2] |
152 |
| -# Vectors structure: [[2, 3, 45, 4], [7.5, 8.3, -120.5, 7.2]] |
153 |
| - |
154 |
| -fig = pygmt.Figure() |
155 |
| -fig.plot( |
156 |
| - region=[0, 10, 0, 10], |
157 |
| - projection="X10c/10c", |
158 |
| - frame="ag", |
159 |
| - data=vectors, |
160 |
| - style="v0.6c+e", |
161 |
| - pen="2p", |
162 |
| - color="red3", |
163 |
| -) |
164 |
| -fig.show() |
165 |
| - |
166 |
| -######################################################################################## |
167 |
| -# In this example, cartesian vectors are plotted over a Mercator |
168 |
| -# projection of the continental US. The x values represent the |
169 |
| -# longitude and y values represent the latitude where the vector starts. |
170 |
| -# |
171 |
| -# This example also shows some of the styles a vector supports. |
172 |
| -# The beginning point of the vector (**+b**) |
173 |
| -# should take the shape of a circle (**c**). Similarly, the end |
174 |
| -# point of the vector (**+e**) should have an arrow shape (**a**) |
175 |
| -# (to draw a plain arrow, use **A** instead). Lastly, the **+a** |
176 |
| -# specifies the angle of the vector head apex (30 degrees in |
177 |
| -# this example). |
178 |
| - |
179 |
| -# Create a plot with coast, Mercator projection (M) over the continental US |
180 |
| -fig = pygmt.Figure() |
181 |
| -fig.coast( |
182 |
| - region=[-127, -64, 24, 53], |
183 |
| - projection="M10c", |
184 |
| - frame="ag", |
185 |
| - borders=1, |
186 |
| - shorelines="0.25p,black", |
187 |
| - area_thresh=4000, |
188 |
| - land="grey", |
189 |
| - water="lightblue", |
190 |
| -) |
191 |
| - |
192 |
| -# Plot a vector using the x, y, direction parameters |
193 |
| -style = "v0.4c+bc+ea+a30" |
194 |
| -fig.plot( |
195 |
| - x=-110, |
196 |
| - y=40, |
197 |
| - style=style, |
198 |
| - direction=[[-25], [3]], |
199 |
| - pen="1p", |
200 |
| - color="red3", |
201 |
| -) |
202 |
| - |
203 |
| -# vector specifications structured as: [x_start, y_start, direction_degrees, length] |
204 |
| -vector_2 = [-82, 40.5, 138, 2.5] |
205 |
| -vector_3 = [-71.2, 45, -115.7, 4] |
206 |
| -# Create a list of lists that include each vector information |
207 |
| -vectors = [vector_2, vector_3] |
208 |
| - |
209 |
| -# Plot vectors using the data parameter. |
210 |
| -fig.plot( |
211 |
| - data=vectors, |
212 |
| - style=style, |
213 |
| - pen="1p", |
214 |
| - color="yellow", |
215 |
| -) |
216 |
| -fig.show() |
217 |
| - |
218 |
| -######################################################################################## |
219 |
| -# Another example of plotting cartesian vectors over a coast plot. This time |
220 |
| -# a Transverse Mercator projection is used. Additionally, :func:`numpy.linspace` |
221 |
| -# is used to create 5 vectors with equal stops. |
222 |
| - |
223 |
| -x = np.linspace(36, 42, 5) # x values = [36. 37.5 39. 40.5 42. ] |
224 |
| -y = np.linspace(39, 39, 5) # y values = [39. 39. 39. 39.] |
225 |
| -direction = np.linspace(-90, -90, 5) # direction values = [-90. -90. -90. -90.] |
226 |
| -length = np.linspace(1.5, 1.5, 5) # length values = [1.5 1.5 1.5 1.5] |
227 |
| - |
228 |
| -# Create a plot with coast, Mercator projection (M) over the continental US |
229 |
| -fig = pygmt.Figure() |
230 |
| -fig.coast( |
231 |
| - region=[20, 50, 30, 45], |
232 |
| - projection="T35/10c", |
233 |
| - frame=True, |
234 |
| - borders=1, |
235 |
| - shorelines="0.25p,black", |
236 |
| - area_thresh=4000, |
237 |
| - land="lightbrown", |
238 |
| - water="lightblue", |
239 |
| -) |
240 |
| - |
241 |
| -fig.plot( |
242 |
| - x=x, |
243 |
| - y=y, |
244 |
| - style="v0.4c+ea+bc", |
245 |
| - direction=[direction, length], |
246 |
| - pen="0.6p", |
247 |
| - color="red3", |
248 |
| -) |
249 |
| - |
250 |
| -fig.show() |
0 commit comments