Credits Overview Plotting Styles Commands Terminals

labels

figure_labels1

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 properties that vary point by point such as text rotation angle (keywords rotate variable) or color (see textcolor variable).

     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). 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. 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

figure_labels2

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

This example shows use of labels with variable rotation angle in column 4 and textcolor ("tc") in column 5. Note that variable color is always taken from the last column in the using specifier.

  plot $Data using 1:2:3:4:5 with labels tc variable rotate variable