Thicker lines in gnuplot legend

I draw some data curves using gnuplot and they look like this:

Plot with thin lines

However, the string patterns in the legend are too thin. When you have more curves, it becomes difficult to distinguish colors. You can increase the thickness of the curves using "line width", for example, adding "lw 3" to the plot command, and you get the following:

Plot with thick lines

However, this increases thickness everywhere. Can lines be made thick in a legend? I know that this can be done "differently" by post-processing in the output .png file. But is there a direct approach using some gnuplot / wizardry settings?

+7
source share
5 answers

Unfortunately, I do not know a way to control the thickness of the lines in the key, since they correspond to the lines that are drawn. You can see what you can change by typing help set key in gnuplot.

Using the multiplier, you can draw the plot lines first without a key, and then draw the key again for the "ghost lines". Here is an example of code that will do this:

 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 command of the graph, function 2 (constant) is displayed with a range of y from 0 to 1, so it is not displayed.

+6
source

I came across this post and it gave me a critical idea. The provided solution does not work in multi-mode, since the second schedule command will call the second schedule, which, most likely, will not be desirable. as a workaround, you can set the source data as "notitle", then display data outside the range with the same line type and color of different thicknesses with the desired name. I will just leave my example. It also includes the linestyles that I announced. So I use the same linestyle (ls) to get the same color, but changing the thickness on the second line.

  # for pngs set terminal pngcairo size 1600,600 font ',18' enhanced set output "pic_multi_kenngr_ana.png set style line 2 lc rgb '#0ce90b' lt 1 lw 1.5 # --- green set style line 3 lc rgb '#09e0b3' lt 1 lw 1.5 # . set style line 4 lc rgb '#065fd8' lt 1 lw 1.5 # . set style line 5 lc rgb '#4e04cf' lt 1 lw 1.5 # . set style line 6 lc rgb '#c702a9' lt 1 lw 1.5 # . set style line 7 lc rgb '#bf000a' lt 1 lw 1.5 # --- red set multiplot layout 1,2 set xtics rotate set tmargin 5 set xtics 12 set grid xtics # set axis labels set ylabel 'T [K]' set xlabel 'Zeit [h]' # select range set xrange [0:48] set yrange [290.15:306.15] set title "(a) Bodentemperatur" set key top right Right plot 'par_crank_hom01lvls.04.dat' u 1:3 with lines ls 7 notitle,\ 'par_crank_str01lvls.16.dat' u 1:3 with lines ls 2 notitle,\ 500 t 'z = 4 cm' ls 7 lw 4,\ 500 t 'z = 16 cm' ls 2 lw 4 ################################################ set title "(b) Bodenwärmestrom an der Oberfläche" set ylabel 'G [W m^{-2}]' set yrange[-110:110] unset key plot 'par_crank_str01_ghf.dat' u 1:3 with lines unset multiplot 

I hope this helps someone

+3
source

An even simpler work (imho) is to clearly define the colors and build each line twice, once with a high lw value for the key, as well as with a heading displayed in the key, but adding "each :: 0 :: 0" that actually ends up doing nothing, and as soon as the normal path. See the following code snippet:

 plot data u 0:1 wl linecolor rgb #1b9e77 lw 2 t "",\ data every ::0::0 u 0:1 wl linecolor rgb #1b9e77 lw 4 t "Title" 
+1
source

To expand the NaN comment from @Svalorzen, below you will see a graph of two lines of width 1 from some datafile.txt file without headers, and the corresponding empty lines with the specified headers and a width of 5 for the key only will be created:

 plot [][]\ NaN title "Title1" w line lt 1 lc 1 lw 5,\ NaN title "Title2" w line lt 1 lc 2 lw 5,\ "datafile.txt" using 1:2 title "" w line lt 1 lc 1 lw 1,\ "datafile.txt" using 1:3 title "" w line lt 1 lc 2 lw 1 
+1
source

I find the answer to this: Set key line width

in your case should be:

 plot '../batteries/9v/carrefour.txt' wl lw 1 linetype 1 notitle, 0/0 linetype 1 linewidth 5 title 'Carrefour' rep '../batteries/9v/philips.txt' wl lw 1 linetype 2 notitle, 0/0 linetype 2 linewidth 5 title 'Philips' rep '../batteries/9v/sony.txt' wl lw 1, linetype 3 notitle, 0/0 linetype 3 linewidth 5 title 'Sony' 
0
source

Source: https://habr.com/ru/post/918220/


All Articles