Credits | Overview | Plotting Styles | Commands | Terminals
--- | --- | --- | --- | ---

## key

The set key command enables a key (or legend) containing 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. The text of the titles is controlled by the set key autotitle option or by the title keyword of individual plot and splot commands.

See key placement for syntax of options that affect where the key is placed. See key layout for syntax of options that affect the content of the key.

Syntax (global options):

          set key {on|off} {default}
                {font "<face>,<size>"} {{no}enhanced}
                {{no}title "<text>" {<font or other text options>}}
                {{no}autotitle {columnheader}}
                {{no}box {<line properties>}} {{no}opaque {fc <colorspec>}}
                {width <width_increment>} {height <height_increment>}
          unset key

By default the key is placed in the upper right inside corner of the graph. The optional font becomes the default for all elements of the key. You can provide an option title for the key as a whole that spans the full width of the key at the top. This title can use different font, color, justification, and enhancement from individual plot titles.

Each component in a plot command is represented in the key by a single line containing corresponding title text and a line or symbol or shape representing the plot style. The title text may be auto-generated or given explicitly in the plot command as title "text". Using the keyword notitle in the plot command will suppress generation of the entire line. If you want to suppress the text only, use title "" in the plot command.

Contour plots generated additional entries in the key (see cntrlabel). You can add extra lines to the key by inserting a dummy plot command that uses the keyword keyentry rather than a filename or a function. See keyentry.

A box can be drawn around the key (box {...}) with user-specified line properties. The height and width increments (specified in character units) are added to or subtracted from the size of the key box. This is useful mainly when you want larger borders around the key entries.

By default the key is built up one plot at a time. That is, the key symbol and title are drawn at the same time as the corresponding plot. That means newer plots may sometimes place elements on top of the key. set key opaque causes the key to be generated after all the plots. In this case the key area is filled with background color or the requested fill color and then the key symbols and titles are written. The default can be restored by set key noopaque.

The text in the key uses enhanced mode by default. This can be suppressed by the noenhanced keyword applied to the entire key, to the key title only, or to individual plot titles.

set key default restores the default key configuration.

         set key notitle
         set key nobox noopaque
         set key fixed right top vertical Right noreverse enhanced autotitle
         set key noinvert samplen 4 spacing 1 width 0 height 0
         set key maxcolumns 0 maxrows 0

Subtopics

- 3D key
- key examples
- extra key entries
- key autotitle

- key layout
- key placement
- key offset
- key samples

- multiple keys