Key

The set key enables a key describing curves on a plot.

Syntax:

        set key { <position> | \
                 left | right | top | bottom | outside | below } \
                { Left | Right } \
                { {no}reverse } \
                { title "<text>" } \
                { {no}box {<linetype>} }
        set nokey
        show key

By default the key is placed in the upper right corner of the plot. The keywords left, right, top, bottom, outside and below may be used to place the key in the other corners inside the plot or to the right (outside) or below the plot. They may be given alone or combined.

Justification of the labels within the key is controlled by Left or Right (default is Right). The text and sample can be reversed (reverse) and a box can be drawn around the key (box {<linetype>}) in a specified linetype. A title can be put on the key (title ''<text>'')—see also syntax for the distinction between text in single- or double-quotes. The title uses the same justification as do the individual labels.

The <position> can be a simple x,y,z as in previous versions, but these can be preceded by one of four keywords (first, second, graph, screen) which selects the co-ordinate system in which the position is specified. See set co-ordinates for more details. The key is drawn as a sequence of lines, with one plot described on each line. On the right-hand side (or the left-hand side, if reverse is selected) of each line is a representation that attempts to mimic the way the curve is plotted. On the other side of each line is the text description, obtained from the plot command. See plot title to change this description. The lines are vertically arranged so that an imaginary straight line divides the left- and right-hand sides of the key. It is the co-ordinates of this line that are specified with the set key command. In a plot, only the x and y co-ordinates are used to specify the line position. For a splot, x, y and z are all used as a 3-d location mapped using the same mapping as the plot itself to form the required 2-d screen position of the imaginary line.

Some or all of the key may be outside of the plot boundary, although this may interfere with other labels and may cause an error on some devices. If you use the keywords outside or below, gnuplot makes space for the keys and the plot becomes smaller. Putting keys outside to the right, they occupy as few columns as possible, and putting them below, as many columns as possible (depending of the length of the labels), thus stealing as little space from the plot as possible.

When using the TeX or PostScript drivers, or similar drivers where formatting information is embedded in the string, gnuplot is unable to calculate correctly the width of the string for key positioning. If the key is to be positioned at the left, it may be convenient to use the combination set key left Left reverse. The box and gap in the grid will be the width of the literal string.

If splot is being used to draw contours, the contour labels will be listed in the key. If the alignment of these labels is poor or a different number of decimal places is desired, the label format can be specified. See set clabel for details.

Examples:

This places the key at the default location:

        set key
This disables the key:
        set nokey
This places a key at co-ordinates 2,3.5,2:
        set key 2,3.5,2
This places the key below the plot:
        set key below
This places the key in the bottom left corner, left-justifies the text, gives it a title, and draws a box around it in linetype 3:
        set key left bottom Left title 'Legend' box 3