Next: Exercises Up: SESSION TWO Previous: More exercises

# Plotting text strings

In many situations we need to annotate plots or maps with text strings; in GMT this is done using pstext . Apart from the common switches, there are 7 options that are particularly useful (Table 2.4).

Table 2.4: Some of the most frequently used options in pstext
Option | Purpose
-–C dx/ dy | Spacing between text and the text box (see -–W)
-–D dx/ dy | Offsets the projected location of the strings
-–G fill | Sets the color of the text
-–L | Lists the font ids and exits
-–N | Deactivates clipping at the borders
-–S pen | Selects outline font and sets pen attributes
-–W[ fill][ o[ pen]] | Paint the text box; draw the outline if o is appended (also see -–C)

Figure 2.1: Relationship between the text box and the extra clearance

The input data to pstext is expected to contain the following information:

x y size angle fontno justify text

The size argument is the font size in points, the angle is the angle (measured counterclockwise) between the text's baseline and the horizontal, justify indicates which point on the text-string should correspond to the given x, y location, and text is the text string or sentence to plot. Figure 2.2 illustrates these concepts and shows the relevant two-character codes used for justification.

Figure 2.2: Justification (and corresponding character codes) for text strings

The text string can be one or several words and may include octal codes for special characters and escape-sequences used to select subscripts or symbol fonts. The following escape sequences are recognized:

Table 2.5: GMT text escape sequences
Code | Effect
@~ | Turns symbol font on or off
@% fontno% | Switches to another font; @%% resets to previous font
@+ | Turns superscript on or off
@- | Turns subscript on or off
@# | Turns small caps on or off
@! | Creates one composite character of the next two characters
@@ | Prints the @ sign itself
@E @e | Æ æ
@O @o | Ø ø
@A @a | Å å

Note that these escape sequences (as well as octal codes) can be used anywhere in GMT including as arguments to the -–B option. A chart of octal codes can be found in Appendix F in the GMT technical reference book. For accented European characters you must set WANT_EURO_FONT to TRUE in your .gmtdefaults file.

We will demonstrate pstext with the following script:

    cat << EOF | pstext –-R0/7/0/7 -–JX7i -–P -–B1g1 -–G255/128/0 | ghostview -
    1	1	30	0	4	BL	It’s P@al, not Pal!
    1	2	30	0	4	BL	Try @%33%ZapfChancery@%% today
    1	3	30	0	4	BL	@~D@~g@-b@- = 2@~pr@~G@~D@~h.
    1	4	30	0	4	BL	University of Hawaii at M@!a\305noa
    EOF

Here we have used the ``here document'' notation in UNIX: The << EOF will treat the following lines as the input file until it detects the word EOF. We pipe the PostScript directly through ghostview (the - tells ghostview that piping is happening).

Next: Exercises Up: SESSION TWO Previous: More exercises