Gnuplot: add key outside plot without resizing plot

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.


Old question but an easy solution is to simply set a rmargin and place the legend inside it. Example:

f(x) = x
g(x) = x**2

set multiplot layout 2,1

set rmargin 30
set key at screen 1, graph 1

plot f(x) title "Legend 1 blablabla"

plot g(x) title "Legend 2"

unset multiplot

example

You only need the margin to be big enough for your legend. Default unit is the character width.