Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

session-2.rst 23 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
  1. Session Two
  2. ===========
  3. General Information
  4. -------------------
  5. There are 18 GMT modules that directly create (or add overlays to)
  6. plots; the remaining 45 are mostly concerned with data
  7. processing. This session will focus on the task of plotting
  8. lines, symbols, and text on maps. We will build on the skills
  9. we acquired while familiarizing ourselves with the various
  10. GMT map projections as well as how to select a data domain
  11. and boundary annotations.
  12. ======================== ====================================================================
  13. Program Purpose
  14. ======================== ====================================================================
  15. **BASEMAPS**
  16. basemap Create an empty basemap frame with optional scale
  17. coast Plot coastlines, filled continents, rivers, and political borders
  18. legend Create legend overlay
  19. **POINTS AND LINES**
  20. wiggle Draw spatial time-series along their (*x,y*)-tracks
  21. plot Plot symbols, polygons, and lines in 2-D
  22. plot3d Plot symbols, polygons, and lines in 3-D
  23. **HISTOGRAMS**
  24. histogram Plot a rectangular histogram
  25. rose Plot a polar histogram(sector/rose diagram)
  26. **CONTOURS**
  27. grdcontour Contouring of grids
  28. contour Direct contouring/imaging of (*x,y,z*) data by optimal triangulation
  29. **SURFACES**
  30. grdimage Project and plot grids or images
  31. grdvector Plot vector fields from grids
  32. grdview 3-D perspective imaging of grids
  33. **UTILITIES**
  34. clip Use polygon files to initiate custom clipping paths
  35. image Plot Sun raster files
  36. mask Create clipping paths or generate overlay to mask
  37. colorbar Plot gray scale or color scale bar
  38. text Plot text strings
  39. ======================== ====================================================================
  40. Plotting lines and symbols, :doc:`/plot` is one of the most frequently
  41. used modules in GMT. In addition to the common command line switches
  42. it has numerous specific options, and expects different file formats
  43. depending on what action has been selected. These circumstances make
  44. :doc:`/plot` harder to master than most GMT tools. The table below
  45. shows an abbreviated list of the options:
  46. ======================================================================= ===================================================================
  47. Option Purpose
  48. ======================================================================= ===================================================================
  49. **-A** Suppress line interpolation along great circles
  50. **-C**\ *cpt* Let symbol color be determined from *z*-values and the *cpt* file
  51. **-E**\ [**x**\|\ **X**][**y**\|\ **Y**][**+w**\ *cap*][**+p**\ *pen*] Draw selected error bars with specified attributes
  52. **-G**\ *fill* Set color for symbol or fill for polygons
  53. **-L**\ [*options*] Explicitly close polygons or create polygon (see :doc:`/plot`)
  54. **-N**\ [**c**\|\ **r**] Do Not clip symbols at map borders
  55. **-S**\ [*symbol*][*size*] Select one of several symbols
  56. **-W**\ *pen* Set *pen* for line or symbol outline
  57. ======================================================================= ===================================================================
  58. The symbols can either be transparent (using **-W** only, not **-G**)
  59. or solid (**-G**, with optional outline using **-W**). The **-S**
  60. option takes the code for the desired symbol and optional size information.
  61. If no symbol is given it is expected to be given in the last column of each record in the input
  62. file. The *size* is optional since individual sizes for
  63. symbols may also be provided by the input data. The main symbols available to
  64. us are shown in the table below:
  65. +------------------------------------+-------------------------------------------------------------------------------------------+
  66. | Option | Symbol |
  67. +====================================+===========================================================================================+
  68. | **-S-**\ *size* | horizontal dash; *size* is length of dash |
  69. +------------------------------------+-------------------------------------------------------------------------------------------+
  70. | **-Sa**\ *size* | st\ **a**\ r; *size* is radius of circumscribing circle |
  71. +------------------------------------+-------------------------------------------------------------------------------------------+
  72. | **-Sb**\ *size*\ [/*base*][*unit*] | **b**\ ar; *size* is bar width, set *unit* be **u** if *size* is in *x*-units |
  73. +------------------------------------+-------------------------------------------------------------------------------------------+
  74. | | Bar extends from *base* [0] to the *y*-value |
  75. +------------------------------------+-------------------------------------------------------------------------------------------+
  76. | **-Sc**\ *size* | **c**\ ircle; *size* is the diameter |
  77. +------------------------------------+-------------------------------------------------------------------------------------------+
  78. | **-Sd**\ *size* | **d**\ iamond; *size* is its side |
  79. +------------------------------------+-------------------------------------------------------------------------------------------+
  80. | **-Se** | **e**\ llipse; *direction* (CCW from horizontal), *major*, and *minor* axes |
  81. +------------------------------------+-------------------------------------------------------------------------------------------+
  82. | | are read from the input file |
  83. +------------------------------------+-------------------------------------------------------------------------------------------+
  84. | **-SE** | **e**\ llipse; *azimuth* (CW from vertical), *major*, and *minor* axes in kilometers |
  85. +------------------------------------+-------------------------------------------------------------------------------------------+
  86. | | are read from the input file |
  87. +------------------------------------+-------------------------------------------------------------------------------------------+
  88. | **-Sg**\ *size* | octa\ **g**\ on; *size* is its side |
  89. +------------------------------------+-------------------------------------------------------------------------------------------+
  90. | **-Sh**\ *size* | **h**\ exagon; *size* is its side |
  91. +------------------------------------+-------------------------------------------------------------------------------------------+
  92. | **-Si**\ *size* | **i**\ nverted triangle; *size* is its side |
  93. +------------------------------------+-------------------------------------------------------------------------------------------+
  94. | **-Sk**\ *symbol*/*size* | **k**\ ustom symbol; *size* is its side |
  95. +------------------------------------+-------------------------------------------------------------------------------------------+
  96. | **-Sl**\ *size*\ **+t**\ *string* | **l**\ etter; *size* is fontsize. The *string* can be a letter or a text string |
  97. +------------------------------------+-------------------------------------------------------------------------------------------+
  98. | | Append **+f**\ *font* to set font and **+j**\ *just* for justification |
  99. +------------------------------------+-------------------------------------------------------------------------------------------+
  100. | **-Sn**\ *size* | pe\ **n**\ tagon; *size* is its side |
  101. +------------------------------------+-------------------------------------------------------------------------------------------+
  102. | **-Sp** | **p**\ oint; no size needed (1 pixel at current resolution is used) |
  103. +------------------------------------+-------------------------------------------------------------------------------------------+
  104. | **-Sr**\ *size* | **r**\ ect, *width* and *height* are read from input file |
  105. +------------------------------------+-------------------------------------------------------------------------------------------+
  106. | **-Ss**\ *size* | **s**\ quare, *size* is its side |
  107. +------------------------------------+-------------------------------------------------------------------------------------------+
  108. | **-St**\ *size* | **t**\ riangle; *size* is its side |
  109. +------------------------------------+-------------------------------------------------------------------------------------------+
  110. | **-Sv**\ *params* | **v**\ ector; *direction* (CCW from horizontal) and *length* are read from input data |
  111. +------------------------------------+-------------------------------------------------------------------------------------------+
  112. | | Append parameters of the vector; see :doc:`/plot` for syntax. |
  113. +------------------------------------+-------------------------------------------------------------------------------------------+
  114. | **-SV**\ *params* | **v**\ ector, except *azimuth* (degrees east of north) is expected instead of *direction* |
  115. +------------------------------------+-------------------------------------------------------------------------------------------+
  116. | | The angle on the map is calculated based on the chosen map projection |
  117. +------------------------------------+-------------------------------------------------------------------------------------------+
  118. | **-Sw**\ [*size*] | pie **w**\ edge; *start* and *stop* directions (CCW from horizontal) are read from |
  119. +------------------------------------+-------------------------------------------------------------------------------------------+
  120. | | input data |
  121. +------------------------------------+-------------------------------------------------------------------------------------------+
  122. | **-Sx**\ *size* | cross; *size* is length of crossing lines |
  123. +------------------------------------+-------------------------------------------------------------------------------------------+
  124. | **-Sy**\ *size* | vertical dash; *size* is length of dash |
  125. +------------------------------------+-------------------------------------------------------------------------------------------+
  126. The symbol option in :doc:`/plot`. Lower case symbols (**a, c, d, g, h, i, n, s, t, x**)
  127. will fit inside a circle of given diameter. Upper case symbols (**A, C, D, G, H, I, N, S, T, X**)
  128. will have area equal to that of a circle of given diameter.
  129. Because some symbols require more input data than others, and because the
  130. size of symbols as well as their color can be determined from the input data,
  131. the format of data can be confusing. The general format for the input data
  132. is (optional items are in brackets []):
  133. ::
  134. x y [ z ] [ size ] [ sigma_x ] [ sigma_y ] [ symbol ]
  135. Thus, the only required input columns are the first two which must contain the
  136. longitude and latitude (or *x* and *y*. The remaining items
  137. apply when one (or more) of the following conditions are met:
  138. #. If you want the color of each symbol to be determined individually,
  139. supply a CPT with the **-C** option and let the 3rd data column
  140. contain the *z*-values to be used with the CPT.
  141. #. If you want the size of each symbol to be determined individually,
  142. append the size in a separate column.
  143. #. To draw error bars, use the **-E** option and give one or two
  144. additional data columns with the *dx* and *dy* values; the form of
  145. **-E** determines if one (**-Ex** or **-Ey**) or two (**-Exy**)
  146. columns are needed. If upper case flags **X** or **Y** are given then
  147. we will instead draw a "box-and-whisker" symbol and the *sigma_x* (or
  148. *sigma_y*) must represent 4 columns containing the minimum, the 25 and 75%
  149. quartiles, and the maximum value. The given *x* (or *y*) coordinate is taken as the 50%
  150. quantile (median).
  151. #. If you draw vectors with **-Sv** (or **-SV**) then *size* is
  152. actually two columns containing the *direction* (or *azimuth*)
  153. and *length* of each vector.
  154. #. If you draw ellipses (**-Se**) then *size* is actually three
  155. columns containing the *direction* and the *major* and *minor*
  156. axes in plot units (with **-SE** we expect *azimuth* instead and axes
  157. lengths in km).
  158. Before we try some examples we need to review two key switches; they
  159. specify pen attributes and symbol or polygon fill. Please consult
  160. the :ref:`General Features <GMT_General_Features>` section the
  161. GMT Technical Reference and Cookbook before experimenting
  162. with the examples below.
  163. Examples:
  164. We will start off using the file tut_data.txt in your directory.
  165. Using the GMT utility :doc:`/gmtinfo` we find the extent of the
  166. data region:
  167. ::
  168. gmt info @tut_data.txt
  169. which returns
  170. ::
  171. tut_data.txt: N = 7 <1/5> <1/5>
  172. telling us that the file tut_data.txt has 7 records and gives the
  173. minimum and maximum values for the first two columns. Given our
  174. knowledge of how to set up linear projections with **-R** and **-JX**,
  175. try the following:
  176. #. Plot the data as transparent circles of size 0.3 inches.
  177. #. Plot the data as solid white circles instead.
  178. #. Plot the data using 0.5" stars, making them red with a thick (width = 1.5p),
  179. dashed pen.
  180. To simply plot the data as a line we choose no symbol and specify a pen thickness instead:
  181. .. literalinclude:: /_verbatim/GMT_tut_7.txt
  182. Your plot should look like :ref:`our example 7 below <gmt_tut_7>`
  183. .. _gmt_tut_7:
  184. .. figure:: /_images/GMT_tut_7.*
  185. :width: 400 px
  186. :align: center
  187. Result of GMT Tutorial example 7
  188. Exercises:
  189. #. Plot the data as a green-blue polygon instead.
  190. #. Try using a predefined pattern.
  191. A common question is : "How can I plot symbols connected by a line
  192. with plot?". The surprising answer is that we must call :doc:`/plot` twice.
  193. While this sounds cumbersome there is a reason for this: Basically,
  194. polygons need to be kept in memory since they may need to be clipped,
  195. hence computer memory places a limit on how large polygons we may plot.
  196. Symbols, on the other hand, can be plotted one at the time so there
  197. is no limit to how many symbols one may plot. Therefore, to connect
  198. symbols with a line we must use the overlay approach:
  199. .. literalinclude:: /_verbatim/GMT_tut_8.txt
  200. Your plot should look like :ref:`our example 8 below <gmt_tut_8>`. The
  201. two-step procedure also makes it easy to plot the line over the symbols
  202. instead of symbols over the line, as here.
  203. .. _gmt_tut_8:
  204. .. figure:: /_images/GMT_tut_8.*
  205. :width: 400 px
  206. :align: center
  207. Result of GMT Tutorial example 8
  208. Our final :doc:`/plot` example involves a more complicated scenario
  209. in which we want to plot the epicenters of several earthquakes over
  210. the background of a coastline basemap. We want the symbols to have a
  211. size that reflects the magnitude of the earthquakes, and that their
  212. color should reflect the depth of the hypocenter. The first few
  213. lines in the remote tut_quakes.ngdc looks like this:
  214. ::
  215. Historical Tsunami Earthquakes from the NCEI Database
  216. Year Mo Da Lat+N Long+E Dep Mag
  217. 1987 01 04 49.77 149.29 489 4.1
  218. 1987 01 09 39.90 141.68 067 6.8
  219. Thus the file has three header records (including the blank line),
  220. but we are only interested in columns 5, 4, 6, and 7. In addition to
  221. extract those columns we must also scale the magnitudes into symbols
  222. sizes in inches. Given their range it looks like multiplying the
  223. magnitude by 0.1 will work well for symbol sizes in cm. Reformatting this file to comply
  224. with the :doc:`/plot` input format can be done in a number of ways,
  225. including manual editing, using MATLAB, a spreadsheet program, or UNIX
  226. tools. Here, we simply use the common column selection option **-i**
  227. and its :ref:`scaling/offset capabilities <-icols_full>`.
  228. To skip the first 3 header records
  229. and then select the 4th, 3rd, 5th, and
  230. 6th column and scale the last column by 0.1, we would use
  231. ::
  232. -i4,3,5,6s0.1 -h3
  233. (Remember that 0 is the first column). We will follow conventional color schemes for seismicity and assign red
  234. to shallow quakes (depth 0-100 km), green to intermediate quakes
  235. (100-300 km), and blue to deep earthquakes (depth > 300 km). The
  236. quakes.cpt file establishes the relationship between depth
  237. and color:
  238. ::
  239. # color palette for seismicity
  240. #z0 color z1 color
  241. 0 red 100 red
  242. 100 green 300 green
  243. 300 blue 1000 blue
  244. Apart from comment lines (starting with #), each record in the CPT
  245. governs the color of a symbol whose *z* value falls in the range between
  246. *z_0* and *z_1*. If the colors for the lower and upper levels differ
  247. then an intermediate color will be linearly interpolated given the *z*
  248. value. Here, we have chosen constant color intervals. You may wish
  249. to consult the :ref:`Color palette tables <CPT_section>` section in the Cookbook.
  250. This color table was generated as part of the script (below).
  251. We may now complete our example using the Mercator projection:
  252. .. literalinclude:: /_verbatim/GMT_tut_9.txt
  253. where the **c** appended to the **-Sc** option ensures that symbols
  254. sizes are interpreted to be in cm. Your plot should look like :ref:`our example 9 below <gmt_tut_9>`
  255. .. _gmt_tut_9:
  256. .. figure:: /_images/GMT_tut_9.*
  257. :width: 400 px
  258. :align: center
  259. Result of GMT Tutorial example 9
  260. More exercises
  261. ~~~~~~~~~~~~~~
  262. #. Select another symbol.
  263. #. Let the deep earthquakes be cyan instead of blue.
  264. Plotting text strings
  265. ---------------------
  266. In many situations we need to annotate plots or maps with text strings;
  267. in GMT this is done using :doc:`/text`. Apart from the common
  268. switches, there are 9 options that are particularly useful.
  269. =================== ===================================================
  270. Option Purpose
  271. =================== ===================================================
  272. **-C**\ *dx*/*dy* Spacing between text and the text box (see **-W**)
  273. **-D**\ *dx*/*dy* Offsets the projected location of the strings
  274. **-F**\ *params* Set font, justify, angle values or source
  275. **-G**\ *fill* Fills the text bos using specified fill
  276. **-L** Lists the font ids and exits
  277. **-N** Deactivates clipping at the borders
  278. **-S**\ *pen* Selects outline font and sets pen attributes
  279. **-T**\ *form* Select text box shape
  280. **-W**\ *pen* Draw the outline of text box
  281. =================== ===================================================
  282. The input data to :doc:`/text` is expected to contain the following
  283. information:
  284. ::
  285. [ x y ] [ font] [ angle ] [ justify ] my text
  286. The *font* is the optional font to use, the *angle* is the
  287. angle (measured counterclockwise) between the text's baseline and the
  288. horizontal, *justify* indicates which anchor point on the text-string should
  289. correspond to the given *x, y* location, and *my text* is the text
  290. string or sentence to plot. See the Technical reference for
  291. the relevant two-character codes used for justification.
  292. The text string can be one or several words and may include octal codes for
  293. special characters and escape-sequences used to select subscripts or symbol
  294. fonts. The escape sequences that are recognized by GMT are given below:
  295. ================== =============================================================
  296. Code Effect
  297. ================== =============================================================
  298. @\~ Turns symbol font on or off
  299. @+ Turns superscript on or off
  300. @- Turns subscript on or off
  301. @\# Turns small caps on or off
  302. @\_ Turns underline on or off
  303. @\%\ *font*\ % Switches to another font; @\%\% resets to previous font
  304. @:\ *size*: Switches to another font size; @:: resets to previous size
  305. @;\ *color*; Switches to another font color; @;; resets to previous color
  306. @! Creates one composite character of the next two characters
  307. @@ Prints the @ sign itself
  308. ================== =============================================================
  309. Note that these escape sequences (as well as octal codes) can be
  310. used anywhere in GMT, including in arguments to the **-B** option.
  311. A chart of octal codes can be found in Appendix F in the GMT
  312. Technical Reference. For accented European characters you must
  313. set :term:`PS_CHAR_ENCODING` to ISOLatin1 in your :doc:`/gmt.conf` file.
  314. We will demonstrate :doc:`/text` with the following script:
  315. .. literalinclude:: /_verbatim/GMT_tut_10.txt
  316. Here we have used the "here document" notation in UNIX: The << EOF
  317. will treat the following lines as the input file until it detects the
  318. word EOF. There is nothing magical about the word EOF; you can use any other
  319. string like STOP, hellobaby, or IamDone.
  320. Your plot should look like :ref:`our example 10 below <gmt_tut_10>`
  321. .. _gmt_tut_10:
  322. .. figure:: /_images/GMT_tut_10.*
  323. :width: 400 px
  324. :align: center
  325. Result of GMT Tutorial example 10
  326. ===== ======== ==== ======
  327. Code Effect Code Effect
  328. ===== ======== ==== ======
  329. @E Æ @e æ
  330. @O Ø @o ø
  331. @A Å @a å
  332. @C Ç @c ç
  333. @N Ñ @n ñ
  334. @U Ü @u ü
  335. @s ß
  336. ===== ======== ==== ======
  337. Exercises:
  338. #. At *y = 5*, add the sentence :math:`z^2 = x^2 + y^2`.
  339. #. At *y = 6*, add the sentence "It is 32° today".
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...