Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reordering gnuplot key entries

Is there a way to change the order of the entries in the key/legend of gnuplot WITHOUT changing the plot command? (I do not mean reversing the entries)

I have multiple lines in one graph and the graphs are automatically generated for a wide range of different input data. I want to have the key entries sorted by their value on the far left of the graph. Changing the plot command is not possible, because this would have to be done for each graph individually.

like image 523
conte.carli Avatar asked Jun 09 '11 09:06

conte.carli


2 Answers

As stated HERE, the key can only be reversed with

set key reverse

Unfortunately, AFAIK a reordering of the key is not possible.

like image 98
Woltan Avatar answered Nov 15 '22 11:11

Woltan


It is possible. What I do is this: The first half of my plot command are the normal plot commands for the lines I want to have in the order I want them. But with the option 'notitle' on each line. The second half of my plot command plot basically empty lines, but with titles in the order I want them to show in the key, of course with the same styles as the plotted lines.

Example code:

    DataFile using 1:4 notitle with lines ls 3,\
    '' using 1:2 notitle with lines ls 1,\
    '' using 1:3 notitle with lines ls 2,\
    EmptyFile title "One" with lines ls 1,\
    '' title "Two" with lines ls 2,\
    '' title "Three" with lines ls 3

Can't remember atm if my EmptyFile contains nothing or just a set of data that is definitely outside my graph area.

like image 41
terter Avatar answered Nov 15 '22 11:11

terter