I want a key in gnuplot that isn't associated with each plotted line but instead represents the specs of each line.
Basically what I want is three colored lines in the key to represent the three algorithms I am using. And then three shapes to represent the error bounds with each algorithm.
So my key would look something like this:
red line — alg 1
blue line — alg 2
green line — alg 3
triangle — 5%
circle — 3%
square — 1%
I'll have 9 lines in my graph that is a combination of color and shape, but I don't want my legend to have all 9 lines, just the representative specs.
I hope this makes sense. Let me know if you need more clarification.
I haven't found many resources on making a key independent of my plotted lines so I've only gotten as far as setting 'notitle' to each line.
Best Answer
One easy way to achieve this is to plot data without a key ("key" is the gnuplot term for what you called a "legend"), and then make a key with no data. This way, the key can contain whatever you want, regardless of the number and styles of data series plotted. I'll call this a "false key" since it's a key, but it's deliberately deceptive as it's not directly generated from the visible data series.
Plotting with a "false key"
First, plot your data and (like you surmised) use the
notitle
keyword so this data doesn't show up in the key. Then, plot nothing usingNaN
(not a number) as the data. You can title it, assign point types, line styles, etc., as you wish. Since they have atitle
, they show up in the key with your given title, and the real data (withnotitle
) does not.For example, I have made a plot using your specification for the key, but with my own lines plotted:
Notice how I have predefined the line styles beforehand. This is to help keep the plotted data (e.g.
f1(x) ls 1 notitle
) in synch with what goes in the key (e.g.NaN ls 1 title "Alg. 1"
). This way, the line style specification only appears once in the code. To change it, you only have to change it in one place.Also notice how the dummy point shapes in the key are plotted
with points
and usinglc rgb "black"
. Making them black shows them as neutral of the red/green/blue-ness of the algorithm lines. This is to suggest to the viewer that the shape represents a different parameter from the color.Suggestion for line style sanity
Your example plot has nine data series. You might try specifying line styles beforehand with something like:
When you plot your data, just use
ls 4
for Alg. 2 (5%),ls 9
for Alg. 3 (1%), etc. With your colors and point types only defined in one place, it is easier to change and keep consistent.Another suggestion: If someone tries to print your plot, it is difficult to distinguish red, green, and blue when printed in black & white. If you use a different line type (dashed, dotted, etc.) for the different algorithm types, this distinction would show up even if printed in B&W. To do this, use a different line type instead of
lt 1
for the different algorithms.