Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gnuplot - alignment of horizontal key titles of different length

I am having difficulty with the alignment of the different key titles when placed horizontally, apparently due to the differing lengths in the titles.

Having two short plot titles (1st and 4th) and two longer titles (2nd and 3rd) it leaves a larger gap between the final two titles (presumably as it is setting the gaps between them all by the same maximum string length). I have searched but found no way to alter this.

A simplified example is shown below. Any suggestions or help would be greatly appreciated.

set terminal postscript eps size 5.12,2.3 enhanced color "Helvetica" 12
set output 'example.eps'

set title 'Difficulty of Long and Short Title usage in Horizontal Keys' font "Helvetica, 20"

set key inside bottom center horizontal font "Helvetica, 20" width 1.8

set ylabel 'ylabel' font "Helvetica, 20" 
set xlabel 'xlabel' font "Helvetica, 20"  
set lmargin screen 0.10
set rmargin screen 0.95
set yrange [-1.5:1.5]

plot sin(x) title 'short', \
cos(x) title 'long title 1', \
-0.5 title 'long title 2', \
0.5 title 'short' w l ls 4

The result is: enter image description here

like image 298
user2707058 Avatar asked Aug 22 '13 12:08

user2707058


1 Answers

One possible workaround for this would be to generate the first three graphs and the last one with two different plot commands in multiplot mode:

set terminal postscript eps size 5.12,2.3 enhanced color "Helvetica" 12
set output 'example.eps'

set title 'Difficulty of Long and Short Title usage in Horizontal Keys' font "Helvetica, 20"

set ylabel 'ylabel' font "Helvetica, 20" 
set xlabel 'xlabel' font "Helvetica, 20"  
set lmargin screen 0.10
set rmargin screen 0.95
set yrange [-1.5:1.5]

set bmargin screen 0.15
set tmargin screen 0.9

set multiplot
set key horizontal font "Helvetica, 20" width 1.8 at graph 0.4, graph 0.1 center maxrows 1
plot sin(x) title 'short', \
     cos(x) title 'long title 1', \
     -0.5 title 'long title 2'

unset title
unset xlabel
unset ylabel
unset border
unset tics
set key horizontal font "Helvetica, 20" width 1.8 at graph 0.84, graph 0.1 center maxrows 1
plot 0.5 title 'short' w l ls 4
unset multiplot

However, this requires some tweaking:

  • Before the second plot you must remove title, labels, tics and border, otherwise the graph might look jagged because of different anti-aliasing
  • To have the same margins you must also set fixed tmargin and bmargin
  • You must position your keys manually

The above code gives you: enter image description here

Now you must judge if its worth.

like image 137
Christoph Avatar answered Nov 15 '22 10:11

Christoph