Custom legend (or text) gnuplot

colors, gnuplot, legend

Solution

There is no option for this, you need to fiddle a bit. Here is YAGH (Yet another gnuplot hack) ;)

Assuming that your values are equidistantly spaced, you can use the `'+'` special filename with the `labels` plotting style.

To show only the custom key, consider the following example:

labels="first second third fourth"
set xrange[0:1] # must be set for '+'
set yrange[0:1]
set samples words(labels)   # number of colors to use
key_x = 0.8     # x-value of the points, must be given in units of the x-axis
key_y = 0.8
key_dy = 0.05
set palette model RGB defined ( 1 'black', 2 'blue', 3 'green', 4 'red')
unset colorbox
plot '+' using (key_x):(key_y + $0*key_dy):(word(labels, int($0+1))):0 \
    with labels left offset 1,-0.1 point pt 7 palette t ''

This gives (with 4.6.4):

As the `set samples` doesn't affect the data plots, you can integrate this directly in your plot command:

...
unset key
plot "file" u 2:1:3 w points pt 14 ps 2 palette, \
     "file2" u 2:1:3 w points pt 14 ps 2 palette, \
     '+' using (key_x):(key_y - $0*key_dy):(word(labels, int($0+1))):0 \
         with labels left offset 1,-0.1 point pt 14 ps 2 palette

But you need to set a proper xrange, yrange and the values of `key_x`, `key_y` and `key_dy`.

This is not the most intuitive way, but it works :)

Problem

I have a file with 3 columns, the first 2 are the position x y and the 3rd one I use it for define the color so I have something like this: ``` set palette model RGB defined ( 1 'black', 2 'blue', 3 'green', 4 'red') unset colorbox plot "file" u 2:1:3 w points pt 14 ps 2 palette, "file2" u 2:1:3 w points pt 14 ps 2 palette ``` Now the question: Is it possible to have a proper legend with this kind of point and COLOR?. Since the points will have different colors (according to the pallete) I want to specify what means each color in the legend. The only solution I was thinking was to write somewhere in the plot some text with the character of the point (in this case pt 14) and specify the color... but is not really a solution right? So please help!

Original source