highsciguy
highsciguy

Reputation: 2647

bring legend to the front in gnuplot

Is there a way to bring the key (legend) in gnuplot (epslatex terminal) to the very front? In my plot I experience that some filledcurves are on top of the small line samples of the key so that these are invisible. The lables in the key are placed on top as they are drawn by latex. I know that I could change the order in the plot (filledcurves first) but I actually want that the filledcurves hide the previously drawn lines in the plot itself.

Upvotes: 8

Views: 9187

Answers (4)

One can use dummy plot-elements with NaN (or keyentry for gnuplot 5.2.6). The key title will not be in front.

Here is a comparison between default, the NaN approach and key opaque.

reset session

set samp 10000
a = 10
set xrange [0:200]

set multiplot layout 2,2

set key title "default"
plot sin(x), cos(x)

set key title "NaNs dummy entries"
plot sin(x) t "", cos(x) t "",\
     NaN t "sin(x)" ls 1, NaN t "cos(x)" ls 2

set key opaque title "key opaque"
plot sin(x), cos(x)

unset multiplot

Upvotes: 0

rehctawrats
rehctawrats

Reputation: 221

@sfeam's answer is correct, as long as the key doesn't have overlap with the border. If it has, there's no way to bring the legend in front of the border, but you can bring the border to the back by "set border back".

So, a combination of "set key opaque" and "set border back" guarantees that the legend is on top of everything.

Upvotes: 0

sfeam
sfeam

Reputation: 276

Recent gnuplot versions allow you to say "set key opaque", which I think does what you want.

Upvotes: 15

Jari Laamanen
Jari Laamanen

Reputation: 2647

First plot your lines without the key plot x notitle ls 1, then plot your filledcurves, then plot yet the extra lines using the linestyles of the first lines, but so that they are out of the visible area:

set yrange [-10:10]
plot -x notitle ls 2, x**2/3-5 w filledc ls 5, x**2+100 t "first-line legend" ls 2 

This gives you the legend at the top of the filledcurves, but the visible lines below. Hope this works with epslatex too.

Upvotes: 1

Related Questions