Plotting text lines and paragraphs
In addition to –R, –J, –B etc., options are:
Option Purpose
–Cdx/dy Spacing between text and the text box (see –W)
–Ddx/dy Offsets the projected location of the strings
–Gfill Sets the color of the text
–L Lists the font ids and exits
–M Paragraph mode [Default is text line mode]
–N Deactivates clipping at the borders
–Spen Selects outline font and sets pen attributes
–W[fill][o|O|c|C[pen]] Paint text box; draw outline by appending o (also see –C)
1
pstext text line input and setup
x y size angle font justify text
x y is map coordinates
size is font size in points
angle is inclination of text baseline w.r.t. horizontal
font is font name or number (see –L)
justify relates (x, y) to a point on the text string
text
2
Exercise 12
Create a simple linear plot and write your
name using a font size of 10pt, font type of
Palatino-Bold and left justified
Get a list of the different types of fonts and
their corresponding font number:
pstext -L
3
Exercise 12 cont ...
x y size angle font justify text
pstext -R0/10/0/6 -JX10 -Ba2f1g2WS -P <<end > ex12.ps
2 4 14 0 31 1 Maria Seton
end
Plot your name on the same graph using
Helvetica-Oblique, font size of 20 but with
a dark green font
Plot your name on the same graph in
magenta using whichever font and font
size you like but the text must be vertical
4
GMT text escape sequences
Code Effect
@~ Turns symbol font on or off
@%font% Change font; @%% resets to past font
@+ Turns superscript on or off
@- Turns subscript on or off
@# Turns small caps on or off
@! Creates composite of next two characters
@@ Prints the @ sign itself
@E or @e Æ or æ
@O or @o Ø or ø
@A or @a Å or å
5
pstext paragraph mode (–M)
Used to typeset justified text such as figure captions
Sub-headings must indicate paragraph parameters:
< x y size angle font justify linespace parwidth parjust
parjust can be l, c, r, j
Sub-header must be followed by one or more text lines
Takes 3 additional escape sequences:
Code Effect
@;r/g/b; Change font color, @;; resets it
@:size: Change font size, @:: resets it
@_ Turn underline on or off
6
Afternoon Exercise 1a
Copy the directory tutorial from my ftpsite
ftp.geosci.usyd.edu.au/pub/marias/
tutorial
7
Afternoon Exercise 1b
Task: Make a global Robinson Map
Create a file with the long, lat locations of 4
cities. You can get these from a file in your
tutorial directory called wcity_major.dat
Plot red squares for 4 cities
Label your cities
8
Afternoon Exercise 1 cont ...
Place justified figure caption in a white,
outlined box in the lower left corner
Caption can be whatever but should take up
more than 2 lines, start with “Figure 1.” and
exercise the underline mechanism a bit
Don’t be afraid to look up man pstext
9
Shell programming
ksh serves several purposes
Accepts commands, checks syntax, expands file
names, redirects i/o.
Allows for customization of environment
Offers job control (&, CTRL-Z, bg, fg)
Provides script programming
The combination of GMT, UNIX tools, and
ksh allow for wide flexibility in attacking
problems
10
ksh variables
To assign variables, use
var=value
var must begin with a letter, may contain
numbers and underscores, but not $, &.
e.g., size2_big=14
e.g., inputfile=quakes.d
To access the variable, use $var
echo $var
You should begin to use variables in your
script
e.g. psfile=ex20.ps 11
UNIX tools
Greatly enhances our scripting capability
Some useful tools
awk Text processing language
sed Text substitution stream editor
grep Pattern matching
wc Word and record counting
head and tail List first and last lines from files
sort General-purpose sorter
12
awk
Most important processing tool
It is often used to reformat data files into a
format that GMT can read
Also used to manipulate data
Automatically works on each record
$1, $2, etc., are the data fields
$0 is the entire record
NR is record number
NF is the number of current fields
13
Examples of awk commands
To print only columns 1 and 2 from a file:
awk ‘{print $1, $2}’ $infile > $outfile
To print columns 1 and 2 in reverse order:
awk ‘{print $2, $1}’ $infile > $outfile
To print column 1 and divide column 2 by 10
awk ‘{print $1, $2/10}’ $infile > $outfile
14
Examples of awk commands
To print only records which contain
“Australia” in the third column:
awk ‘{if ($3 == “Australia”) print $1,
$2, $3, $4}’ $infile > $outfile
To print only records which do not contain
“Australia” in the third column:
awk ‘{if ($3 != “Australia”) print $1,
$2, $3, $4}’ $infile > $outfile
15
Smithsonian Volcano Catalog
We will be using data from the Smithsonian
Volcano Catalog (http://
www.volcano.si.edu/gvp/world/
summinfo.cfm)
Located in your tutorial directory
(volcanoes.dat)
Open the file and see what it contains
16
Map Exercise 13
Plotting the GVP data
We will write a script that
1. Makes a global Hammer projection map
with blue oceans and light brown
continents
2. Plots volcanoes as red triangles
17
1. Plotting the background
Basic pscoast job, no further instructions
needed!
18
Reformatting the data
Lucky for you, we have already formatted
the volcano dataset -
volcanoes_processed.dat
Make your plot!
19
Pacific Seamount Catalog
You have a file in your tutorial directory called:
Pacific_ages.d
It has ages of seamounts, islands, and
plateaus in the Pacific. Look at this file in
Notepad++.
20
Afternoon Exercise 2
Make Mercator map of Hawaii-Emperor area
Extract records for Hawaii-Emperor only
[seamounts_pac.d]
Plot dated seamounts/islands using color-coded
triangles [psxy –C]
Color-code triangles based on age [makecpt]
Plot volcanoes using a different symbol [psxy]
Plot the number of samples in the title [wc]
Place your color table beneath the map [psscale]
21
22
Map exercise 11
Task: use minmax to determine data domain
of the file data, and use psxy to plot data
as transparent circles of size 0.6 cm.
minmax data
psxy data –R0/6/0/6 –JX12 –B2g1 –Sc0.6 –W0.5p -P > ex11.ps
pstopdf ex11.ps
23
Map exercise 11 cont ...
Plot as solid white circles
Plot using 0.8 cm red stars with thick
(1.5p), dashed green pen for star outline
Plot as line data (no symbols)
Plot as filled polygon using your favorite
color
Plot solid line with inverted triangles (0.6
cm) at points
24
Example: Seismicity map
We want to plot the epicenters of
earthquakes over a background Mercator
coastline map. We will use data from the
tutorial directory we just copied over (data
set quakes.ngdc and color table
quakes.cpt). In particular, our map should
have circles whose:
size scale with earthquake magnitude
color reflect hypocenter depth.
25
quakes.ngdc
Historical tsunamigenic earthquakes from NGDC
Plain ASCII data table with 3 header records:
Historical Tsunami Earthquakes from the
NGDC Database
Year Mo Da Lat+N Long+E Dep Mag
1987 01 04 49.77 149.29 489 4.1
1987 01 09 39.90 141.68 067 6.8
1987 01 09 39.82 141.64 084 4.0
...
26
Converting quakes.ngdc
We want input records with lon lat depth
size
We choose size = 0.04 * magnitude
The UNIX tool awk can do this for us:
awk ‘{if (NR > 3) print $5, $4, $6,
0.04*$7}’ quakes.ngdc > quakes.d
Output now looks like:
149.29 49.77 489 0.082
141.68 39.90 067 0.136
...
27
Assigning quake colors
Typical seismicity color scheme is:
Red for shallow quakes (0-100 km)
Green for middle depths (100-300 km)
Blue for deep quakes (> 300 km)
# color palette for seismicity
#z0 start-color z1 end-color
0 red 100 red
100 green 300 green
300 blue 1000 blue
28
Map exercise 12
Task: Write a script that plots historical seismicity on
top of a Mercator geographic map as specified
above. Pick contrasting colors for your map. Add a
map scale (–L).
pscoast -R130/150/35/50 -JM12 -B5WSne -P -Ggray -K
-Lf134/49/42.5/500
psxy -R -JM -O -Cquakes.cpt quakes.d -Sc -W0.25p
Select another symbol
Let deep earthquakes be cyan instead
29
Map exercise 12 cont ....
Select a new region
Plot the new region on the same page together
with the old one
Eliminate the intermediate file quakes.d
30
31
Advanced exercise
Recreate the following plot. Hint: you
need to change CHAR_ENCODING.
32