Gnuplot key box

gnuplot

I am trying to move the box of this key (legend) in gnuplot.
It looks like this right now but I want the key to be centered in the box.

enter image description here

If I make the box smaller the key makes a part of the box to disappear as well as can be seen in this picture

enter image description here.

The code used the produce the first plot below is:

set xlabel 'Time'
set ylabel 'Rad/s'
set title 'Top 1'
set key box width 2 height 3 opaque
plot 'top1lspin.txt' using 1:5 with lines title '{/Symbol ~y{1.1.}}'

The same affect can be seen with other plot commands, e.g.:

set xlabel 'Time'
set ylabel 'Rad/s'
set title 'Top 1'
set key box width 2 height 3 opaque
plot sin(x) title '{/Symbol ~y{1.1.}}'

Best Answer

Without using some LaTeX-based terminal which would offer much more control than just the limited set of enhanced postscript commands, I am afraid that there are just "ugly" solutions to the problem.

One might:

  1. dispense with the border on set key, generate the legend as is and then draw a "fake" border using set rectangle. However, the placement of the box here is rather annoying...
  2. trick Gnuplot into using a "proper" alignment inside the legend as in the example below. The idea is to prepend an auxiliary character with under-printed character which will offset the over-printed dot over the "real" character \psi. This will provide more-or-less fine alignment with respect to the line sample in the legend. Alignment with respect to the box is then achieved by appending a phantom space.

In total:

set terminal postscript enhanced color
set output 'test.ps'

set xlabel 'x'
set ylabel 'y'
set title 'Top 1'
set key box vertical width 2 height 1 maxcols 1 spacing 3

set xr [0:pi]
set xtics nomirror
set ytics nomirror

plot \
    sin(x) w l lw 3 lc rgb 'red' t '{/Symbol y}', \
    cos(x) w l lw 3 lc rgb 'blue' t '@{/Symbol ~&{y}{-1.0&{.}}}{/Symbol ~y{0.8.}}@{/Symbol &{y}}'

this then produces:

enter image description here

Related Topic