Search code examples
keylabelgnuplotlegend

Gnuplot, how to include a space character in key titles?


I want to use key titles like "Best F" "Worst F" for a gnuplot 4.4 graph, when reading the data from a file, but I can't figure out how to put the space, e.g.:

Generation Best_F Worst_F Average_F
     5        4     9         5
     4        3     9         4

I tried writing in the file "Best F", "Best%20F" "Best\ F" but they get split, when read as column headers, or I get the ugly looking "%20".

plot for[col=2:4] data.dat using 1:col title columnheader(col)

Or is there a way to do a character substitution, like "Best_F"%" "->"Best F"? replace("_", "\ ", columheader(col))?

I am using terminals wxt and pngcairo (no latex). Thanks


Solution

  • Per the Datastrings section of the manual (that's an old version, but unfortunately later ones haven't been published in HTML), strings in data files are delimited with double quotes. If I modify your example data file to be like this, then I get titles with spaces, when I run it under gnuplot 4.6 patchlevel 1 (with datastrings enabled).

    Generation "Best F" "Worst F" "Average F"
         5        4     9         5
         4        3     9         4
    

    Program:

    plot for[col=2:4] "data.txt" using 1:col title columnheader(col)
    

    Output excerpt:

    enter image description here