String constants, string variables, and string functions

In addition to string constants, most gnuplot commands also accept a string variable, a string expression, or a function that returns a string. For example, the following four methods of creating a plot all result in the same plot title:

     four = "4"
     graph4 = "Title for plot #4"
     graph(n) = sprintf("Title for plot #%d",n)

     plot 'data.4' title "Title for plot #4"
     plot 'data.4' title graph4
     plot 'data.4' title "Title for plot #".four
     plot 'data.4' title graph(4)

Since integers are promoted to strings when operated on by the string concatenation operator ('.' character), the following method also works:

     N = 4
     plot 'data.'.N title "Title for plot #".N

In general, elements on the command line will only be evaluated as possible string variables if they are not otherwise recognizable as part of the normal gnuplot syntax. So the following sequence of commands is legal, although probably should be avoided so as not to cause confusion:

     plot = "my_datafile.dat"
     title = "My Title"
     plot plot title title


Subsections