gnuplot An Interactive Plotting Program Thomas Williams & Colin Kelley Version 3.5 organized by: Alex Woo Version 3.6a organized by: Alexander Lehmann Major contributors (alphabetic order): * John Campbell * Robert Cunningham * Gershon Elber * Roger Fearick * David Kotz * Ed Kubaitis * Russell Lang * Alexander Lehmann * Carsten Steger * Tom Tkacik * Jos Van der Woude * Alex Woo Copyright (C) 1986 - 1993 Thomas Williams, Colin Kelley Mailing list for comments: info-gnuplot@dartmouth.edu Mailing list for bug reports: bug-gnuplot@dartmouth.edu This manual is for GNUPLOT version 3.6a --------------------------------------------------------------------------- Alex Woo, woo@playfair.stanford.edu --------------------------------------------------------------------------- gnuplot GNUPLOT is a command-driven interactive function plotting program. For help on any topic, type help followed by the name of the topic. The new GNUPLOT user should begin by reading the introduction topic (type help introduction) and about the plot command (type help plot). Additional help can be obtained from the USENET newsgroup comp.graphics.gnuplot. copyright introduction cd clear command line-editing comment environment exit expressions fit help if load call pause plot print pwd quit replot reread reset save set-show shell splot start-up substitution update user-defined bugs list of demos --------------------------------------------------------------------------- copyright Copyright (C) 1986 - 1993 Thomas Williams, Colin Kelley Permission to use, copy, and distribute this software and its documentation for any purpose with or without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. Permission to modify the software is granted, but not the right to distribute the modified code. Modifications are to be distributed as patches to released version. This software is provided "as is" without express or implied warranty. AUTHORS Original Software: Thomas Williams, Colin Kelley. Gnuplot 2.0 additions: Russell Lang, Dave Kotz, John Campbell. Gnuplot 3.0 additions: Gershon Elber and many others. There is a mailing list for gnuplot users. Note, however, that the newsgroup comp.graphics.gnuplot is identical to the mailing list (they both carry the same set of messages). We prefer that you read the messages through that newsgroup, to subscribing to the mailing list. (If you can read that newsgroup, and are already on the mailing list, please send a message info-gnuplot-request@dartmouth.edu, asking to be removed from the mailing list.) The address for mailing to list members is info-gnuplot@dartmouth.edu and for mailing administrative requests is info-gnuplot-request@dartmouth.edu The mailing list for bug reports is bug-gnuplot@dartmouth.edu The list of those interested in beta-test versions is info-gnuplot-beta@dartmouth.edu --------------------------------------------------------------------------- introduction GNUPLOT is a command-driven interactive function plotting program. It is case sensitive (commands and function names written in lowercase are not the same as those written in CAPS). All command names may be abbreviated, as long as the abbreviation is not ambiguous. Any number of commands may appear on a line, separated by semicolons (;). Strings are indicated with quotes. They may be either single or double quotation marks, e.g., load "filename" cd 'dir' Any command-line arguments are assumed to be names of files containing GNUPLOT commands, with the exception of standard X11 arguments, which are processed first. Each file is loaded with the load command, in the order specified. GNUPLOT exits after the last file is processed. When no load files are named, gnuplot enters into an interactive mode. Commands may extend over several input lines, by ending each line but the last with a backslash (\). The backslash must be the LAST character on each line. The effect is as if the backslash and newline were not there. That is, no white space is implied, nor is a comment terminated. Therefore, commenting out a continued line comments out the entire command (see comment). In this documentation, curly braces ({}) denote optional arguments to many commands, and a vertical bar (|) separates mutually exclusive choices. GNUPLOT keywords or help topics are indicated by backquotes or boldface (where available). Angle brackets (<>) are used to mark replaceable tokens. For help on any topic, type help followed by the name of the topic. The new GNUPLOT user should begin by reading about the plot command (type help plot). Simple Plots Demo --------------------------------------------------------------------------- cd The cd command changes the working directory. Syntax: cd "" The directory name must be enclosed in quotes. Examples: cd 'subdir' cd ".." --------------------------------------------------------------------------- clear The clear command erases the current screen or output device as specified by set output. This usually generates a formfeed on hardcopy devices. Use set terminal to set the device type. --------------------------------------------------------------------------- command line-editing The Unix, Atari, VMS, MS-DOS and OS/2 versions of GNUPLOT support command line-editing. Also, a history mechanism allows previous commands to be edited, and re-executed. After the command line has been edited, a newline or carriage return will enter the entire line regardless of where the cursor is positioned. The editing commands are as follows: Line-editing: ^B moves back a single character. ^F moves forward a single character. ^A moves to the beginning of the line. ^E moves to the end of the line. ^H and DEL delete the previous character. ^D deletes the current character. ^K deletes from current position to the end of line. ^L,^R redraws line in case it gets trashed. ^U deletes the entire line. ^W deletes the last word. History: ^P moves back through history. ^N moves forward through history. On the IBM PC the use of a TSR program such as DOSEDIT or CED may be desired for line editing. For such a case GNUPLOT may be compiled with no line editing capability (default makefile setup). Set READLINE in the makefile and add readline.obj to the link file if GNUPLOT line editing is to be used for the IBM PC. The following arrow keys may be used on the IBM PC and Atari versions if readline is used: Left Arrow - same as ^B. Right Arrow - same as ^F. Ctl Left Arrow - same as ^A. Ctl Right Arrow - same as ^E. Up Arrow - same as ^P. Down Arrow - same as ^N. The Atari version of readline defines some additional key aliases: Undo - same as ^L. Home - same as ^A. Ctrl Home - same as ^E. ESC - same as ^U. Help - help' plus return. Ctrl Help - help '. (The readline function in gnuplot is not the same as the readline used in GNU BASH and GNU EMACS. It is somewhat compatible however.) --------------------------------------------------------------------------- comment Comments are supported as follows: a # may appear in most places in a line and GNUPLOT will ignore the rest of the line. It will not have this effect inside quotes, inside numbers (including complex numbers), inside command substitutions, etc. In short, it works anywhere it makes sense to work. --------------------------------------------------------------------------- environment A number of shell environment variables are understood by GNUPLOT. None of these are required, but may be useful. If GNUTERM is defined, it is used as the name of the terminal type to be used. This overrides any terminal type sensed by GNUPLOT on start up, but is itself overridden by the .gnuplot (or equivalent) start-up file (see start-up), and of course by later explicit changes. On Unix, AmigaDOS, AtariTOS, MS-DOS and OS/2, GNUHELP may be defined to be the pathname of the HELP file (gnuplot.gih). On VMS, the symbol GNUPLOT$HELP should be defined as the name of the help library for GNUPLOT. On Unix, HOME is used as the name of a directory to search for a .gnuplot file if none is found in the current directory. On AmigaDOS, AtariTOS, MS-DOS and OS/2, GNUPLOT is used. On VMS, SYS$LOGIN: is used. See help start-up. On Unix, PAGER is used as an output filter for help messages. On Unix, AtariTOS and AmigaDOS, SHELL is used for the shell command. On MS-DOS and OS/2, COMSPEC is used for the shell command. On AmigaDOS, GNUFONT is used for the screen font. For example: "setenv GNUFONT sapphire/14". On MS-DOS, if the BGI interface is used, the variable BGI is used to point to the full path of the BGI drivers directory. Furthermore SVGA is used to name the Super VGA BGI driver in 800x600 res., and its mode of operation as 'Name.Mode'. E.g., if the Super VGA driver is C:\TC\BGI\SVGADRV.BGI and mode 3 is used for 800x600 res., then: 'set BGI=C:\TC\BGI' and 'set SVGA=SVGADRV.3'. --------------------------------------------------------------------------- exit The commands exit and quit and the END-OF-FILE character will exit GNUPLOT. All these commands will clear the output device (as the clear command does) before exiting. --------------------------------------------------------------------------- expressions In general, any mathematical expression accepted by C, FORTRAN, Pascal, or BASIC is valid. The precedence of these operators is determined by the specifications of the C programming language. White space (spaces and tabs) is ignored inside expressions. Complex constants may be expressed as the {,}, where and must be numerical constants. For example, {3,2} represents 3 + 2i; {0,1} represents i itself. The curly braces are explicitly required here. functions operators --------------------------------------------------------------------------- functions The functions in GNUPLOT are the same as the corresponding functions in the Unix math library, except that all functions accept integer, real, and complex arguments, unless otherwise noted. The sgn function is also supported, as in BASIC. abs acos arg asin atan besj0 besj1 besy0 besy1 ceil cos cosh erf erfc exp floor gamma ibeta inverf igamma imag invnorm int lgamma log log10 norm rand real sgn sin sinh sqrt tan tanh --------------------------------------------------------------------------- abs The abs function returns the absolute value of its argument. The returned value is of the same type as the argument. For complex arguments, abs(x) is defined as the length of x in the complex plane [i.e., sqrt(real(x)**2 + imag(x)**2) ]. --------------------------------------------------------------------------- acos The acos function returns the arc cosine (inverse cosine) of its argument. acos returns its argument in radians. --------------------------------------------------------------------------- arg The arg function returns the phase of a complex number, in radians. --------------------------------------------------------------------------- asin The asin function returns the arc sin (inverse sin) of its argument. asin returns its argument in radians. --------------------------------------------------------------------------- atan The atan function returns the arc tangent (inverse tangent) of its argument. atan returns its argument in radians. --------------------------------------------------------------------------- besj0 The besj0 function returns the j0th Bessel function of its argument. besj0 expects its argument to be in radians. --------------------------------------------------------------------------- besj1 The besj1 function returns the j1st Bessel function of its argument. besj1 expects its argument to be in radians. --------------------------------------------------------------------------- besy0 The besy0 function returns the y0th Bessel function of its argument. besy0 expects its argument to be in radians. --------------------------------------------------------------------------- besy1 The besy1 function returns the y1st Bessel function of its argument. besy1 expects its argument to be in radians. --------------------------------------------------------------------------- ceil The ceil function returns the smallest integer that is not less than its argument. For complex numbers, ceil returns the smallest integer not less than the real part of its argument. --------------------------------------------------------------------------- cos The cos function returns the cosine of its argument. cos expects its argument to be in radians. --------------------------------------------------------------------------- cosh The cosh function returns the hyperbolic cosine of its argument. cosh expects its argument to be in radians. --------------------------------------------------------------------------- erf The erf function returns the error function of the real part of its argument. If the argument is a complex value, the imaginary component is ignored. --------------------------------------------------------------------------- erfc The erfc function returns 1.0 - the error function of the real part of its argument. If the argument is a complex value, the imaginary component is ignored. --------------------------------------------------------------------------- exp The exp function returns the exponential function of its argument (e raised to the power of its argument). --------------------------------------------------------------------------- floor The floor function returns the largest integer not greater than its argument. For complex numbers, floor returns the largest integer not greater than the real part of its argument. --------------------------------------------------------------------------- gamma The gamma function returns the gamma function of the real part of its argument. For integer n, gamma(n+1) = n! . If the argument is a complex value, the imaginary component is ignored. --------------------------------------------------------------------------- ibeta The ibeta function returns the incomplete beta function of the real parts of its arguments. p, q > 0 and x in [0:1] If the arguments are complex, the imaginary components are ignored. --------------------------------------------------------------------------- inverf The inverf function returns the inverse error function of the real part of its argument. --------------------------------------------------------------------------- igamma The igamma function returns the incomplete gamma function of the real parts of its arguments. a > 0 and x >= 0 If the arguments are complex, the imaginary components are ignored. --------------------------------------------------------------------------- imag The imag function returns the imaginary part of its argument as a real number. --------------------------------------------------------------------------- invnorm The invnorm function returns the inverse normal distribution function of the real part of its argument. --------------------------------------------------------------------------- int The int function returns the integer part of its argument, truncated toward zero. --------------------------------------------------------------------------- lgamma The lgamma function returns the natural logarithm of the gamma function of the real part of its argument. If the argument is a complex value, the imaginary component is ignored. --------------------------------------------------------------------------- log The log function returns the natural logarithm (base e) of its argument. --------------------------------------------------------------------------- log10 The log10 function returns the logarithm (base 10) of its argument. --------------------------------------------------------------------------- norm The norm function returns the normal distribution function (or Gaussian) of the real part of its argument. --------------------------------------------------------------------------- rand The rand function returns a pseudo random number in the interval [0:1] using the real part of its argument as a seed. If seed < 0 the sequence is (re)initialized. If the argument is a complex value, the imaginary component is ignored. --------------------------------------------------------------------------- real The real function returns the real part of its argument. --------------------------------------------------------------------------- sgn The sgn function returns 1 if its argument is positive, -1 if its argument is negative, and 0 if its argument is 0. If the argument is a complex value, the imaginary component is ignored. --------------------------------------------------------------------------- sin The sin function returns the sine of its argument. sin expects its argument to be in radians. --------------------------------------------------------------------------- sinh The sinh function returns the hyperbolic sine of its argument. sinh expects its argument to be in radians. --------------------------------------------------------------------------- sqrt The sqrt function returns the square root of its argument. --------------------------------------------------------------------------- tan The tan function returns the tangent of its argument. tan expects its argument to be in radians. --------------------------------------------------------------------------- tanh The tanh function returns the hyperbolic tangent of its argument. tanh expects its argument to be in radians. Use of functions and complex variables for airfoils --------------------------------------------------------------------------- operators The operators in GNUPLOT are the same as the corresponding operators in the C programming language, except that all operators accept integer, real, and complex arguments, unless otherwise noted. The ** operator (exponentiation) is supported, as in FORTRAN. Parentheses may be used to change order of evaluation. binary unary --------------------------------------------------------------------------- binary The following is a list of all the binary operators and their usages: Symbol Example Explanation ** a**b exponentiation * a*b multiplication / a/b division % a%b * modulo + a+b addition - a-b subtraction == a==b equality != a!=b inequality & a&b * bitwise AND ^ a^b * bitwise exclusive OR | a|b * bitwise inclusive OR && a&&b * logical AND || a||b * logical OR ?: a?b:c * ternary operation (*) Starred explanations indicate that the operator requires integer arguments. Logical AND (&&) and OR (||) short-circuit the way they do in C. That is, the second && operand is not evaluated if the first is false; the second || operand is not evaluated if the first is true. The ternary operator evaluates its first argument (a). If it is true (non-zero) the second argument (b) is evaluated and returned, otherwise the third argument (c) is evaluated and returned. --------------------------------------------------------------------------- unary The following is a list of all the unary operators and their usages: Symbol Example Explanation - -a unary minus ~ ~a * one's complement ! !a * logical negation ! a! * factorial (*) Starred explanations indicate that the operator requires an integer argument. The factorial operator returns a real number to allow a greater range. --------------------------------------------------------------------------- fit This implementation incorporates the capabiblity of nonlinear least squares fit by using the Marquardt-Levenberg-Algorithm. It may fit every user-defined function to any set of data pairs (x,y). x, y and the function's return type MUST be real! Any variable occuring in the function body may serve as fit parameter (fitting functions without adjustable parameters make no sense). The syntax is: fit {using x:y{:dy}} or fit {using x:y{:dy}} via , , ... is a previously user-defined function of the form: f(x) is treated as in the plot-command. The default column for x is 1, for y is 2. They may be changed by the using x:y mechanism. The optional dy specifies a column containing individual uncertainties for each y-value. These will then be used as weights during the fit. If they aren't given all uncertainties are assumed equally distributed. The start parameters may be specified in a (load-) file wherein each line is of the form: varname = value (comments, separated by '#' and blank lines are also possible). The form varname = value # FIXED means that the variable is treated as a fixed parameter that is initialized but will not be adjusted. It is not necessary (but sometimes useful for clarity) to specify them at all. The keyword '# FIXED' has to appear in exactly this form. The other possibility of specifying start values is that the current value of a variable during the GNUPLOT session shall serve as start parameter. In this case the syntax including the via keyword may be used where only the adjustable variables' names must be given. After each iteration step a detailed info is given about the fit's state both on the screen and on a logfile "fit.log". This file will never be erased but always appended so that the fit's history isn't lost. After each iteration step the fit may be interrupted by pressing ctrl-C (any key BUT ctrl-C under MSDOS). Then you have the possibility of stopping (and accepting the current parameter values) or continuing the fit or of executing a gnuplot command specified by an environment variable FIT_SCRIPT. E.g. a plot command or LOADing some file may be useful. Special GNUPLOT variables: FIT_INDEX: This variable always contains the current data point number during execution starting with 1. You may use it in your fit function to implement multiple-branch-fits. FIT_SKIP: You may specify a positive integer to always skip i data points during fitting. This increases execution speed by the price of less exact results. FIT_LIMIT: may be specified to change the default epsilon limit (1e-5). When the sum of squared residuals changes between 2 iteration steps by less than a factor of this number, the fit is considered as 'converged'. Environment variables: FIT_LOG changes the logfile's path from './fit.log' (write permission is necessary). FIT_SCRIPT specifies a command to be executed after an user interrupt Examples: f(x) = a*x**2 + b*x + c fit f(x) 'measured.dat' 'start.par' fit f(x) 'measured.dat' using 3:7 'start.par' fit f(x) './data/trash.dat' using 1:2:3 via a, b, c SEE ALSO: update --------------------------------------------------------------------------- help The help command displays on-line help. To specify information on a particular topic use the syntax: help {} If is not specified, a short message is printed about GNUPLOT. After help for the requested topic is given, help for a subtopic may be requested by typing its name, extending the help request. After that subtopic has been printed, the request may be extended again, or simply pressing return goes back one level to the previous topic. Eventually, the GNUPLOT command line will return. --------------------------------------------------------------------------- if The if command allows commands to be executed conditionally. Syntax: if () The will be evaluated, if it is true (non-zero), then the command(s) of the will be executed. If the is false (equals zero), then the entire is ignored. Note that use of ';' to allow multiple commands on the same line will NOT end the conditionalized commands. Examples: pi=3 if (pi!=acos(-1)) pause 0 "?Fixing pi!";pi=acos(-1);show variables will display: ?Fixing pi! Variables: pi = 3.14159 or if (1==2) pause 0 "Never see this";pause 0 "Or this either" will not display anything. --------------------------------------------------------------------------- load The load command executes each line of the specified input file as if it had been typed in interactively. Files created by the save command can later be loaded. Any text file containing valid commands can be created and then executed by the load command. Files being loaded may themselves contain load (or call) commands. See comment for information about comments in commands. The load command must be the last command on the line. Syntax: load "" The name of the input file must be enclosed in quotes. Examples: load 'work.gnu' load "func.dat" The load command is performed implicitly on any file names given as arguments to GNUPLOT. These are loaded in the order specified, and then GNUPLOT exits. --------------------------------------------------------------------------- call The call command is identical to the load command with one exception: you can have up to 10 additional parameters to the command (delimited according to the standard parser rules) which can be substituted into the lines read from the file. As each line is read from the called input-file it is scanned for the sequence $ (dollar-sign) followed by a digit (0-9). If found, the sequence is replaced by the corresponding parameter from the call command line. If the parameter was specified as a string in the call line, it is substituted without its enclosing quotes. $ followed by any character other than a digit will be that character. (E.g. use $$ to get a single $.) Providing more than 10 parameters on the call command line will cause an error. A parameter that was not provided, substitutes as nothing. Files being called may themselves contain call or load commands. The call command must be the last command on the line. Syntax: call "" ... The name of the input file must be enclosed in quotes. Examples: if the file 'calltest.gp' contains the line: pause 0 "p0=$0 p1=$1 p2=$2 p3=$3 p4=$4 p5=$5 p6=$6 p7=x$7x" entering the command: call 'calltest.gp' "abcd" 1.2 + "'quoted'" -- "$2" will display: p0=abcd p1=1.2 p2=+ p3='quoted' p4=- p5=- p6=$2 p7=xx --------------------------------------------------------------------------- pause The pause command displays any text associated with the command and then waits a specified amount of time or until the carriage return is pressed. pause is especially useful in conjunction with load files. Syntax: pause