gnuplotlegendpresentation

Thicker lines in the legend of gnuplot


I'm plotting some data curves with gnuplot, and they look like this:

Plot with thin lines

However, the line samples in the legend are too thin. When you have more curves, it becomes hard to distinguish the colors. You can increase the thickness of the curves using "linewidth", e.g., by adding "lw 3" to the plot command, and you'd get this:

Plot with thick lines

However, this increases the thickness everywhere. Is it possible to make the lines thick in the legend only? I know it can be done "the other way", by postprocessing on the output .png file. But is there a direct approach, using some gnuplot setting/wizardry?


Solution

  • Unfortunately, I don't know a way to control the thickness of the lines in the key, since they correspond to the lines being drawn. You can see what you can change by typing help set key in gnuplot.

    Using multiplot, you can draw the plot lines first without the key, then draw the key again for 'ghost lines'. Here is a code sample which would do that:

    set terminal png color size 800,600
    set output 'plot.png'
    
    set multiplot
    
    unset key
    
    plot '../batteries/9v/carrefour.txt' w lp, \
         '../batteries/9v/philips.txt' w lp, \
         '../batteries/9v/sony.txt' w lp
    
    set key; unset tics; unset border; unset xlabel; unset ylabel
    
    plot [][0:1] 2 title 'Carrefour' lw 4, \
         2 title 'Philips' lw 4, \
         2 title 'Sony' lw 4
    

    In the second plot command, the function 2 (a constant) is being plotted with a y range of 0 to 1, so it doesn't show up.