"B " eq "AB ") evaluates as true, illustrating the string concatenation operator and the string equality operator.Ī string which contains a numerical value is promoted to the corresponding integer or real value if used in a numerical expression. Gnuplot can also perform simple operations on strings and string variables. Or you can use the pre-defined variable NaN to achieve the same result. The integer expression "1/0 " may be used to generate an "undefined " flag, which causes a point to be ignored. Try a test like "print -5/2 " to determine if your system always rounds down (-5/2 yields -3) or always rounds toward zero (-5/2 yields -2). The result of division of a negative integer by a positive one may vary among compilers. In mixed expressions, integers are "promoted " to reals before evaluation: 5/2e0 = 2.5. The most important difference between the two forms is in division: division of integers truncates: 5/2 = 2 division of reals does not: 5.0/2.0 = 2.5. Note that gnuplot uses both "real " and "integer " arithmetic, like FORTRAN and C.
White space (spaces and tabs) is ignored inside expressions. The precedence of these operators is determined by the specifications of the C programming language. Here is an example: 1 0.Expressions In general, any mathematical expression accepted by C, FORTRAN, Pascal, or BASIC is valid. The data files are text files formatted into two columns (I use t as a separator), with the first column representing the x values, and the other the y values. We can plot multiple sets of data on the same image by separating the files with a comma. The title specified along with this command will appear in the legend. Set ylabel allows us to specify the title of the y axis, and set title determines the title of the entire plot.įinally, plot "mypoints.dat" title "Method 1" takes the data from the file mypoints.dat and plots it on our image. Set grid will display a grid on the graph. Leaving the range empty, as in our xrange example, will use autoscale, and using reverse will reverse the direction of the axis. Set xrange and set yrange allow us to set the range of the x and y axes. Another useful format might be %P: multiples of Pi. The %g format specifier will select the shortest between floating-point notation ( %f) and exponential notation ( %e). Set format xy "%g" will set the format of the axis tick labels. The show commands simply give some feedback on the command line when gnuplot runs, they’re not actually affecting the generated image. Set logscale xy sets the x and y axes to logarithmic scale. Set output determines what the output file should be named.
The rest of the first line, size 900,675 enhanced font 'Verdana,9' sets the size of the output file to 900×675 pixels size and the font to Verdana size 9. wxt will open a window showing the image instead of saving it to a file.
Changing png to svg, for instance, will generate an SVG file. The set terminal command allows us to set the output format for our graphic. You can execute this script (saved as t, for instance) on linux by running gnuplot t. Plot "mypoints.dat" title "Method 1", "mypoints2.dat" title "Method 2" Set title "Error of derivative estimation" Here is a sample gnuplot script – see a brief explanation of the commands below: set terminal png size 900,675 enhanced font 'Verdana,9' Gnuplot is a very easy-to-use tool allowing us to quickly plot data we generated with, for instance, a C++ program.