Gnuplot, Multiplot: Mix normal and parametric plot with a single legend box?

gnuplot

Solution

Here's a VERY dirty hack that works for me. change:

plot sin(x) title "sinus"

to:

plot sin(x) title "sinus",NaN w l ls 2 lt 2 title "parametric line"

Then plot the parametric line without a title (e.g. `notitle` instead of `title "parametric line"`).

This works because gnuplot ignores NaN's when plotting -- Essentially the second thing we're plotting above just adds one element to the legend. I specify the linetype, etc to be the same as your parametric plot linestyle/type so that it shows up properly in the legend. To my knowledge, this is the only way to do something like this...

Of course, you could just edit it so that both are plotted parametrically and forgo the entire multiplot buisness...

set xrange [0:2*pi]
set yrange [-1:1]
set parametric
set trange [-10:10]
plot t,sin(t) title "Hello", 0.62,t title "World"

that's probably the "cleaner" solution...(but less fun working with gnuplot "magic")

Problem

I create overlapping graphs in Gnuplot, because I mix normal and parametric plots (and also pm3d maps and parametric surfaces). This works fine mostly, except for one thing: If both plots have a title, the legends usually overlaps. A typical example looks like this: ``` #legends.gp set term pngcairo enhanced color linewidth 1.5 dashed dashlength 1.4 rounded set output "legends.png" set title "legends test" set multiplot # make a box around the legend set key box set border 15 lw 1 # fix the margins, this is important to ensure alignment of the plots. set lmargin at screen 0.15 set rmargin at screen 0.98 set tmargin at screen 0.90 set bmargin at screen 0.15 set xlabel "x" set ylabel "sin(x)" set xrange[0:2*pi] set yrange[-1:1] set grid x y # add single tic at 0.62 set xtics add ("x0" 0.62) # main plot command plot sin(x) title "sinus" # turn everything off set format x "" #numbers off set format y "" set xlabel "" #label off set ylabel "" set border 0 #border off unset xtics #tics off unset ytics unset grid #grid off unset title #title off #plot vertical line at 0.62 set parametric plot 0.62,t ls 2 lw 2 title "parametric Line" unset parametric unset multiplot ``` My question is now, is there a simple, mostly automatic way to create a single legend for multiple plots? P.S. Sorry, I ended up making the example file more complex than it had to be by showing some more features, that are hopefully helpful for future readers.

Original source