1.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 colour can also be specified, if desired, using the with colour modifier. For example, the following would produce a green label at the origin:

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

The size of the text in such labels can 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 textcolour command can be used to globally set the colour 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 colour from the present palette, or by a colour name. A list of the recognised colour names can be found in Section 8.4. For example:

set textcolour 2
set textcolour 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, centre or right, and the latter takes the options bottom, centre or top, for example:

set texthalign right
set textvalign top

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 colour 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 = "$\backslash $$\backslash $alpha" ; }
if (m-n==2) { ; GreekLetter = "$\backslash $$\backslash $beta" ; }
if (m-n==3) { ; GreekLetter = "$\backslash $$\backslash $gamma" ; }
if (m-n$<$4)
{
set label an "$\backslash $parbox{5cm}{$\backslash $footnotesize$\backslash $center{$\backslash $
%s-$%s$$\backslash $$\backslash $newline $%d$\backslash $to%d$$\backslash $$\backslash $newline %s$\backslash $$\backslash $newline}}" $\backslash $
%(SeriesName,GreekLetter,n,m,wl) at wl,0.55+0.2*(m-n) $\backslash $
hal centre val centre
}
an = an+1
}
n=n+1
}

# Label astronomical photometric colours
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 centre val centre
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 centre

# Finally produce plot
plot [80*unit(nm):5500*unit(nm)][0:1.25]

\includegraphics[width=11cm]{examples/eps/ex_hlines}


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 width 20

# 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 ’{$\backslash $large $\backslash $sf $\backslash $slshape Western Australia}’ 117, -28
set label 2 ’{$\backslash $large $\backslash $sf $\backslash $slshape South Australia}’ 130, -29.5
set label 3 ’{$\backslash $large $\backslash $sf $\backslash $slshape Northern Territory}’ 129.5, -20.5
set label 4 ’{$\backslash $large $\backslash $sf $\backslash $slshape Queensland}’ 141,-24
set label 5 ’{$\backslash $large $\backslash $sf $\backslash $slshape New South Wales}’ 142,-32.5
set label 6 ’{$\backslash $large $\backslash $sf $\backslash $slshape Victoria}’ 139,-41
set arrow 6 from 141,-40 to 142, -37 with nohead
set label 7 ’{$\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 ’{$\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 ’{$\backslash $sf Perth}’ 116.5, -32.4
set label 11 ’{$\backslash $sf Adelaide}’ 136, -38
set arrow 11 from 137.5,-37.2 to 138.601, -34.929
set label 12 ’{$\backslash $sf Darwin}’ 131, -13.5
set label 13 ’{$\backslash $sf Brisbane}’ 149, -27.5
set label 14 ’{$\backslash $sf Sydney}’ 151.5, -34.5
set label 15 ’{$\backslash $sf Melbourne}’ 143, -37.3
set label 16 ’{$\backslash $sf Hobart}’ 147.5, -44.25
set label 17 ’{$\backslash $sf Canberra}’ 145, -35.25

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

# Plot the coastline and cities
plot [][-45:] ’ex_map_1.dat.gz’ every ::1 with lines, $\backslash $
’ex_map_2.dat’ with points pointtype 10 pointsize 2

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