next up previous contents index
Next: Key placement Up: Set-show Previous: Isosamples   Contents   Index


Key

The set key command enables a key (or legend) describing plots on a plot.

The contents of the key, i.e., the names given to each plotted data set and function and samples of the lines and/or symbols used to represent them, are determined by the title and with options of the {s}plot command. Please see plot title (p. [*]) and plot with (p. [*]) for more information.

Syntax:

     set key {on|off} {default}
             {{inside | outside} | {lmargin | rmargin | tmargin | bmargin}
               | {at <position>}}
             {left | right | center} {top | bottom | center}
             {vertical | horizontal} {Left | Right}
             {{no}reverse} {{no}invert}
             {samplen <sample_length>} {spacing <vertical_spacing>}
             {width <width_increment>}
             {height <height_increment>}
             {{no}autotitle {columnheader}}
             {title "<text>"} {{no}enhanced}
             {font "<face>,<size>"} {textcolor <colorspec>}
             {{no}box { {linestyle | ls <line_style>}
                        | {linetype | lt <line_type>}
                          {linewidth | lw <line_width>}}}
     unset key
     show key

The key contains a title and a sample (line, point, box) for each plot in the graph. The key may be turned off by requesting set key off or unset key. Individual key entries may be turned off by using the notitle keyword in the corresponding plot command.

Elements within the key are stacked according to vertical or horizontal. In the case of vertical, the key occupies as few columns as possible. That is, elements are aligned in a column until running out of vertical space at which point a new column is started. In the case of horizontal, the key occupies as few rows as possible.

By default the key is placed in the upper right inside corner of the graph. The keywords left, right, top, bottom, center, inside, outside, lmargin, rmargin, tmargin, bmargin (, above, over, below and under) may be used to automatically place the key in other positions of the graph. Also an at 4#4position5#5 may be given to indicate precisely where the plot should be placed. In this case, the keywords left, right, top, bottom and center serve an analogous purpose for alignment. For more information, see key placement (p. [*]).

Justification of the plot titles within the key is controlled by Left or Right (default). The text and sample can be reversed (reverse) and a box can be drawn around the key (box {...}) in a specified linetype and linewidth, or a user-defined linestyle.

By default the first plot label is at the top of the key and successive labels are entered below it. The invert option causes the first label to be placed at the bottom of the key, with successive labels entered above it. This option is useful to force the vertical ordering of labels in the key to match the order of box types in a stacked histogram.

The 4#4height_increment5#5 is a number of character heights to be added to or subtracted from the height of the key box. This is useful mainly when you are putting a box around the key and want larger borders around the key entries.

All plotted curves of plots and splots are titled according to the default option autotitles. The automatic generation of titles can be suppressed by noautotitles; then only those titles explicitly defined by (s)plot ... title ... will be drawn.

The command set key autotitle columnheader causes the first entry in each column of input data to be interpreted as a text string and used as a title for the corresponding plot. If the quantity being plotted is a function of data from several columns, gnuplot may be confused as to which column to draw the title from. In this case it is necessary to specify the column explicitly in the plot command, e.g.


     plot "datafile" using (($2+$3)/$4) title columnhead(3) with lines

An overall title can be put on the key (title "4#4text5#5") -- see also syntax (p. [*]) for the distinction between text in single- or double-quotes. The key title uses the same justification as do the plot titles.

The defaults for set key are on, right, top, vertical, Right, noreverse, noinvert, samplen 4, spacing 1.25, title "", and nobox. The default 4#4linetype5#5 is the same as that used for the plot borders. Entering set key default returns the key to its default configuration.

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 (the line title), obtained from the plot command. The lines are vertically arranged so that an imaginary straight line divides the left- and right-hand sides of the key. It is the coordinates of the top of this line that are specified with the set key command. In a plot, only the x and y coordinates are used to specify the line position. For a splot, x, y and z are all used as a 3D location mapped using the same mapping as the graph itself to form the required 2D screen position of the imaginary line.

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 (p. [*]) for details.

Examples:

This places the key at the default location:

     set key default

This disables the key:

     unset key

This places a key at coordinates 2,3.5,2 in the default (first) coordinate system:

     set key at 2,3.5,2

This places the key below the graph:

     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



Subsections
next up previous contents index
Next: Key placement Up: Set-show Previous: Isosamples   Contents   Index
2011-11-17