8.11.2 Text labels

Text labels may be placed on plots using the set label command. As with all textual labels in Pyxplot, these are rendered in latex:

set label 1 'Hello World' at 0,0

As in the previous section, the number 1 is a reference number, which allows the label to be removed by either of the following two commands:

set nolabel 1
unset label 1

The positional coordinates for the text label, placed after the at keyword, can be specified in any of the coordinate systems described for arrows above. As above, either two or three coordinates may be supplied. A rotation angle may optionally be specified after the keyword rotate, to rotate text counter-clockwise by a given angle, measured in degrees. For example, the following would produce upward-running text:

set label 1 'Hello World' at axis3 3.0, axis4 2.7 rotate 90

A color can also be specified, if desired, using the with color modifier. For example, the following would produce a green label at the origin:

set label 2 'This label is green' at 0, 0 with color green

The size of the text can be set using the with fontsize modifier:

set label 3 'A Big Blue Label' at 0,0 with col blue fontsize 4

Alternatively, it may be set globally using the set fontsize command. This applies not only to the set label command, but also to plot titles, axis labels, keys, etc. The value supplied should be a multiplicative factor greater than zero; a value of 2 would cause text to be rendered at twice its normal size, and a value of 0.5 would cause text to be rendered at half its normal size.

The set textcolor command can be used to globally set the color of all text output, and applies to all of the text that the set fontsize command does. It is especially useful when producing plots to be embedded in presentation slideshows, where bright text on a dark background may be desired. It should be followed either by an integer, to set a color from the present palette, or by a color name. A list of the recognised color names can be found in Section 19.4. For example:

set textcolor 2
set textcolor blue

By default, each label’s specified position corresponds to its bottom left corner. This alignment may be changed with the set texthalign and set textvalign commands. The former takes the options left, center or right, and the latter takes the options bottom, center or top, for example:

set texthalign right
set textvalign top


Example: A diagram of the atomic lines of hydrogen

The wavelengths of the spectral lines of atomic hydrogen are given by the Rydberg formula,
  \[  \frac{1}{\lambda } = R_\mathrm {H}\left(\frac{1}{n^2}-\frac{1}{m^2}\right),  \]    
where $\lambda $ is wavelength, $R_\mathrm {H}$ is the Rydberg constant, predefined in Pyxplot as the variable phy_Ry, and n and m are positive non-zero integers such that m>n. The first few series are called the Lyman series (n$=1$), the Balmer series (n$=2$), the Paschen series (n$=3$) and the Brackett series (n$=4$). Within each series, the lines are given Greek letter designations – $\alpha $ for m$=$n$+1$, $\beta $ for m$=$n$+2$, and so forth.
In the following example, we produce a diagram of the lines in the first four series, drawing the first 20 lines within each. At the bottom of the diagram, we overlay indications of the wavelengths of ten color filters commonly used by astronomers (data taken from Binney & Merrifield, Galactic Astronomy, Princeton, 1998).
set numeric display latex
set width 20
set size ratio 0.4
set numerics sf 4
set log x
set x1label "Wavelength"
set x2label "Frequency"     ; set unit of frequency Hz
set x3label "Photon Energy" ; set unit of energy eV
set axis x2 linked x1 using phy.c/x
set axis x3 linked x2 using phy.h*x
set noytics ; set nomytics

# Draw lines of first four series of hydrogen lines
an=2
n=1
foreach SeriesName in ["Ly","Ba","Pa","Br"]
 {
  for m=n+1 to n+21
   {
    wl = 1/(phy.Ry*(1/n**2-1/m**2))
    set arrow an from wl,0.3 to wl,0.6 with nohead col n
    if (m-n==1) { ; GreekLetter = r"$\backslash $alpha" ; }
    if (m-n==2) { ; GreekLetter = r"$\backslash $beta"  ; }
    if (m-n==3) { ; GreekLetter = r"$\backslash $gamma" ; }
    if (m-n$<$4)
     {
      set label an r"$\backslash $parbox{5cm}{$\backslash $footnotesize$\backslash $center{$\backslash $
        %s-$%s$$\backslash $newline $%d$\backslash $to%d$$\backslash $newline %s$\backslash $newline}}" $\backslash $
        %(SeriesName,GreekLetter,m,n,wl) at wl,0.55+0.2*(m-n) $\backslash $
        hal center val center
     }
    an = an+1
   }
  n=n+1
 }

# Label astronomical photometric colors
foreach datum i,name,wl_c,wl_w in "–" using $\backslash $
    1:"%s"%($2):($3*unit(nm)):($4*unit(nm))
 {
  arry = 0.12+0.1*(i%2) # Vertical positions for arrows
  laby = 0.07+0.1*(i%2) # Vertical positions for labels
  x0 = (wl_c-wl_w/2) # Shortward end of passband
  x1 =  wl_c         # Centre of passband
  x2 = (wl_c+wl_w/2) # Longward end of passband
  set arrow an from x0,arry to x2,arry with nohead
  set label an name at x1,laby hal center val center
  an = an+1
 }
 1 U  365   66
 2 B  445   94
 3 V  551   88
 4 R  658  138
 5 I  806  149
 6 J 1220  213
 7 H 1630  307
 8 K 2190  390
 9 L 3450  472
10 M 4750  460
END

# Draw a marker for the Lyman limit
ll = 91.1267*unit(nm)
set arrow 1 from ll,0.12 to ll,0.22
set label 1 "Lyman Limit: %s"%(ll) at 95*unit(nm),0.17 $\backslash $
     hal left val center

# Finally produce plot
plot [80*unit(nm):5500*unit(nm)][0:1.25]
\includegraphics[width=11cm]{examples/eps/ex_hlines}



Example: A map of Australia

In this example, we use Pyxplot to plot a map of Australia, using a coastal outline obtained from http://www.maproom.psu.edu/dcw/. We use the set label command to label the states and major cities. The files ex_­map_­1.dat.gz and ex_­map_­2.dat can be found in the Pyxplot installation tarball in the directory doc/­examples/.
set size 20 ratio (45-10)/(154-112)*cos(25*unit(deg))
set xrange [112:154]
set yrange [-45:-10]

# We want a plot without axes or key
set nokey
set axis x invisible
set axis y invisible

# Labels for the states
set label 1 r’{$\backslash $large $\backslash $sf $\backslash $slshape Western Australia}’ 117, -28
set label 2 r’{$\backslash $large $\backslash $sf $\backslash $slshape South Australia}’ 130, -29.5
set label 3 r’{$\backslash $large $\backslash $sf $\backslash $slshape Northern Territory}’ 129.5, -20.5
set label 4 r’{$\backslash $large $\backslash $sf $\backslash $slshape Queensland}’ 141,-24
set label 5 r’{$\backslash $large $\backslash $sf $\backslash $slshape New South Wales}’ 142,-32.5
set label 6 r’{$\backslash $large $\backslash $sf $\backslash $slshape Victoria}’ 139,-41
set arrow 6 from 141,-40 to 142, -37 with nohead
set label 7 r’{$\backslash $large $\backslash $sf $\backslash $slshape Tasmania}’ 149,-42
set arrow 7 from 149, -41.5 to 146.5, -41.75 with nohead
set label 8 r’{$\backslash $large $\backslash $sf $\backslash $slshape Capital Territory}’ 151,-37
set arrow 8 from 151, -36.25 to 149, -36 with nohead

# Labels for the cities
set label 10 r’{$\backslash $sf Perth}’ 116.5, -32.4
set label 11 r’{$\backslash $sf Adelaide}’ 136, -38
set arrow 11 from 137.5,-37.2 to 138.601, -34.929
set label 12 r’{$\backslash $sf Darwin}’ 131, -13.5
set label 13 r’{$\backslash $sf Brisbane}’ 149, -27.5
set label 14 r’{$\backslash $sf Sydney}’ 151.5, -34.5
set label 15 r’{$\backslash $sf Melbourne}’ 143, -37.3
set label 16 r’{$\backslash $sf Hobart}’ 147.5, -44.25
set label 17 r’{$\backslash $sf Canberra}’ 145, -35.25

# A big label saying "Australia"
set label 20 r’{$\backslash $Huge $\backslash $sf $\backslash $slshape Australia}’ 117,-42

# Plot the coastline and cities
plot ’map_1.dat.gz’ every ::1 with lines, $\backslash $
     ’map_2.dat’ with points pointtype 17 pointsize 2

\includegraphics[width=\textwidth ]{examples/eps/ex_map}