Legend Modification in Gnuplot 4.6

Viewed 94

Hello fellow stackoverflow users,

I have been sitting for several days on the following problem with which I need your help. I would like to create a plot for my thesis, which should resemble the embedded plot.

1

Line type, etc all pose no problem at all. However, I would like to create a similar legend in my plot. I don't even know what keywords to search for. I have tried a few things from other stackoverflow posts i found, but nothing provides an adequate result.

1 Answers

Good question, and I don't know of a good way to produce the type of legend you ask for. The lines and numbers (the "body" of the table, so to say) can be achieved rather easily with the maxrows option of set key.

But the real challenge are the column headers. In gnuplot, a key entry is always build from a sample of the plot style (line, point...) and a text string. I first tried to add the column headers via keyentry, however, this will not give any string at the place where the plot sample would be. I can only suggest a workaround: Build the table body as a key, and add the column headers with a manually placed label.

array numbers[4] = [0.60, 0.64, 0.68, 0.70]
set key t r maxrows 4 vertical width -5 at graph 0.95, 0.9
set label 1 '{/:Italic t}/ms Flamelet DNS  ' at graph 0.95,0.925 r
plot for [i=1:4] i*x w l lc i t sprintf('%.2f', numbers[i]), for [i=1:4] i w p lc i t ' '

Assuming that you use LaTeX for your thesis, you could of course replace the formatting in the label to LaTeX syntax: set label 1 '$t$/ms .... Most probably the amount of spaces will need several iterations of finetuning before you are happy with the result.

But maybe someone else has a nicer, less "hacky" solution?

PS: arrays require gnuplot >= 5.2, in 4.6 you might instead use a string of numbers and split it with word(), however, this has no effect on the approach. Anyway, you might consider updating, the current stable release is 5.4.

enter image description here

Related