Gnuplot: add key outside plot without resizing plot

Alan Turing picture Alan Turing · Dec 9, 2012 · Viewed 26.7k times · Source

In gnuplot, I can put the key outside the plots using this command:

set key outside;
set key right top;

But as this page indicates, the placement of the key will automatically resize the plot area such that the size of the resulting image remains the same. Is there an easy way of keeping the plot area the same no matter where I place the key outside the plot area?

Answer

Lee Phillips picture Lee Phillips · Dec 11, 2012

The size of the plot in units of the canvas size is set with the "set size" command. But the key is considered part of the plot, so the actual graph will always shrink when you use "set key outside", so that the graph + key obey the size that you set with "set size".

What you need to do is first make room for the key by shrinking the plot horizontally, say by "set size .75, 1". Then position the key manually. Rather than saying "set key outside", try "set key at x,y", where x and y are in your axes units. The value of x will be some margin + key length + x-axis length, and the value of y will be somewhat less than the top of your y-axis. You will want to experiment a little to get the placement that you like, but you will find that the graph size does not change as you move the key around using this command.