Labels

The labels style reads coordinates and text from a data file and places the text string at the corresponding 2D or 3D position. 3 or 4 input columns of basic data are required. Additional input columns may be used to provide information such as variable font size or text color (see rgbcolor variable (p. [*])).

    3 columns:  x  y  string    # 2D version
    4 columns:  x  y  z  string # 3D version

The font, color, rotation angle and other properties of the printed text may be specified as additional command options (see set label (p. [*])). The example below generates a 2D plot with text labels constructed from the city whose name is taken from column 1 of the input file, and whose geographic coordinates are in columns 4 and 5. The font size is calculated from the value in column 3, in this case the population.

 CityName(String,Size) = sprintf("{/=%d %s}", Scale(Size), String)
 plot 'cities.dat' using 5:4:(CityName(stringcolumn(1),$3)) with labels

If we did not want to adjust the font size to a different size for each city name, the command would be much simpler:

 plot 'cities.dat' using 5:4:1 with labels font "Times,8"

If the labels are marked as hypertext then the text only appears if the mouse is hovering over the corresponding anchor point. See hypertext (p. [*]). In this case you must enable the label's point attribute so that there is a point to act as the hypertext anchor:

 plot 'cities.dat' using 5:4:1 with labels hypertext point pt 7

The labels style can also be used in place of the points style when the set of predefined point symbols is not suitable or not sufficiently flexible. For example, here we define a set of chosen single-character symbols and assign one of them to each point in a plot based on the value in data column 3:

 set encoding utf8
 symbol(z) = "∙□+⊙♠♣♡♢"[int(z):int(z)]
 splot 'file' using 1:2:(symbol($3)) with labels

See also datastrings (p. [*]), set style data (p. [*]).

Build Daemon user 2016-05-04