Eular
Eular

Reputation: 1817

Gnuplot legend with two boxes/groups and custom heading

I have two types of data/plot and I want to group them for clarification. For example, lets say I have this four data plots

set key box
pl x, x**2, sin(x), cos(x)

And the legend box comes out to be something like
enter image description here

But what I want is something like this, (with two box for each group and a custom heading for each group)

what_I_want

How do I do this? Is this type of legend possible with gnuplot?

Upvotes: 1

Views: 213

Answers (2)

Tom Solid
Tom Solid

Reputation: 2484

I fear, that there is no bulit-in solution in Gnuplot for that. But you can try with multiplot:

set key box
set key width 3

set multiplot

set key at screen 0.45,0.95
set key title "Polynomial"

plot[-10:10][-20:100] x t 'x', x**2 t 'x^2'

set key at screen 0.65,0.95
set key title "Trigonometrical"

plot[-10:10][-20:100] sin(x) lc 3, cos(x) lc 4

unset multiplot

Result

EDIT

As Eldrad wrote, you can fine tuning this solution by setting the margins and unsetting the tics and border of the second plot. Eg.:

set key box
set key width 3

set multiplot

set lmargin screen 0.05
set rmargin screen 0.95
set bmargin screen 0.05
set tmargin screen 0.95
set key at screen 0.45,0.95
set key title "Polynomial"
set tics
set border

plot[-10:10][-20:100] x t 'x', x**2 t 'x^2'

set key at screen 0.65,0.95
set key title "Trigonometrical"
unset tics
set border 0

plot[-10:10][-20:100] sin(x) lc 3, cos(x) lc 4

unset multiplot

Upvotes: 0

Eldrad
Eldrad

Reputation: 743

There is no straightforward option to create two keys, but there are definitely several workarounds that will need manual adjustment. One approach could be creating a two-column key:

set key maxrows 3 width 5
plot keyentry t "Polynomial", x t "x", x**2 t "x²", keyentry t "Trigonometry", sin(x), cos(x)

enter image description here

Another approach might be based on the multiple keys section in the manual.

Upvotes: 1

Related Questions