?copyright Copyright (C) 1986 - 1993, 1996 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 appears 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 the 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. ?introduction ? `gnuplot` is a command-driven interactive function and data 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 (with the exception that `load` or `call` must be the final command), separated by semicolons (;). Strings are indicated with quotes. They may be either single or double quotation marks, e.g., load "filename" cd 'dir' although there are some subtle differences (see `syntax` for more details). 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. Many `gnuplot` commands have multiple options. These options must appear in the proper order, although unwanted ones may be omitted in most cases. Thus if the entire command is "command a b c", then "command a c" will probably work, but "command c a" will fail. 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`). But note that if an error occurs somewhere on a multi-line command, the parser may not be able to locate precisely where the error is and in that case will not necessarily point to the correct line. In this document, curly braces ({}) denote optional arguments 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 on-line help on any topic, type `help` followed by the name of the topic or just `help` or `?` to get a menu of available topics. The new `gnuplot` user should begin by reading about the `plot` command (if on-line, type `help plot`). ?seeking-assistance There is a mailing list for `gnuplot` users. Note, however, that the newsgroup comp.graphics.apps.gnuplot is identical to the mailing list (they both carry the same set of messages). We prefer that you read the messages through the newsgroup rather than subscribing to the mailing list. Administrative requests should be sent to majordomo@dartmouth.edu Send a message with the body (not the subject) consisting of the single word "help" (without the quotes) for more details. The address for mailing to list members is: info-gnuplot@dartmouth.edu Bug reports and code contributions should be mailed to: bug-gnuplot@dartmouth.edu The list of those interested in beta-test versions is: info-gnuplot-beta@dartmouth.edu There is also a World Wide Web page with up-to-date information, including known bugs: http://www.cs.dartmouth.edu/gnuplot Before seeking help, please check the FAQ (Frequently Asked Questions) list. If you do not have a copy of the FAQ, you may request a copy by email from the Majordomo address above, or see the WWW `gnuplot` page. When posting a question, please include full details of the version of `gnuplot`, the machine, and operating system you are using. A _small_ script demonstrating the problem may be useful. Function plots are preferable to datafile plots. If email-ing to info-gnuplot, please state whether or not you are subscribed to the list, so that users who use news will know to email a reply to you. There is a form for such postings on the WWW site. ?what's new in version 3.6 Gnuplot version 3.6 contains many new features. This section gives a partial list and links to the new items in no particular order. 1. `fit f(x) 'file' via` uses the Levenberg-Marquardt method to fit data. (This is only slightly different from the `gnufit` patch available for 3.5.) 2. Greatly expanded `using` command. 3. `set timefmt` allows for the use of dates as input and output for time series plots. See timedat.dem. 4. Multiline labels and font selection in some drivers. 5. Minor (unlabeled) tics. See `set mxtics`. 6. `key` options for moving the key box in the page (and even outside of the plot), putting a title on it and a box around it, and more. 7. Multiplots on a single logical page with `set multiplot`. 8. Enhanced `postscript` driver with super/subscripts and font changes. (This was a separate driver (`enhpost`) that was available as a patch for 3.5.) 9. Second axes: use the top and right axes independently of the bottom and left, both for plotting and labels. See `plot`. 10. Special datafile names `'-'` and `""`. See `plot special-filenames`. 11. Additional coordinate systems for labels and arrows. See `coordinates`. 12. `set size` tries to plot with a specified aspect ratio. 13. `set missing` now treats missing data correctly. 14. The `call` command: `load` with arguments. 15. More flexible `range` commands with `reverse` and `writeback` keywords. 16. `set encoding` for multi-lingual encoding. 17. New `x11` driver with persistent and multiple windows. 18. New plotting styles: `xerrorbars`, `histeps`, `financebars` and more. See `set style`. 19. New tic label formats, including `"%l %L"` which uses the mantissa and exponents to a given base for labels. See `set format`. 20. New drivers, including `cgm` for inclusion into MS-Office applications and `gif` for serving plots to the WEB. 21. Smoothing and spline-fitting options for `plot`. See `plot smooth`. 22. `set margin` and `set origin` give much better control over where a graph appears on the page. 23. `set border` now controls each border individually. 24. The new commands `if` and `reread` allow command loops. 25. Point styles and sizes, line types and widths can be specified on the `plot` command. Line types and widths can also be specified for grids, borders, tics and arrows. See `plot with`. ?line-editing ?editing ?history ?command-line-editing Command-line editing is supported by the Unix, Atari, VMS, MS-DOS and OS/2 versions of `gnuplot`. 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 without regard to where the cursor is positioned. (The readline function in `gnuplot` is not the same as the readline used in GNU Bash and GNU Emacs. If the GNU version is desired, it may be selected instead of the `gnuplot` version at compile time.) 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. The default makefile assumes that this is the case; by default `gnuplot` will be compiled with no line-editing capability. If you want to use `gnuplot`'s line editing, set READLINE in the makefile and add readline.obj to the link file. 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. Ctrl Left Arrow - same as ^A. Ctrl 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 `. ?comments 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. ?coordinates The commands `set arrow`, `set key`, and `set label` allow you to draw something at an arbitrary position on the graph. This position is specified by the syntax: {} , {} {,{} } Each can either be `first`, `second`, `graph` or `screen`. `first` places the x, y, or z coordinate in the system defined by the left and bottom axes; `second` places it in the system defined by the second axes (top and right); `graph` specifies the area within the axes---0,0 is bottom left and 1,1 is top right (for splot, 0,0,0 is bottom left of plotting area; use negative z to get to the base---see `set ticslevel`); and `screen` specifies the screen area (the entire area---not just the portion selected by `set size`), with 0,0 at bottom left and 1,1 at top right. If the coordinate system for x is not specified, `first` is used. If the system for y is not specified, the one used for x is adopted. If one (or more) axis is timeseries, the appropriate coordinate should be given as a quoted time string according to the `timefmt` format string. See `set xdata` and `set timefmt`. `gnuplot` will also accept an integer expression, which will be interpreted as seconds from 1 January 2000. ?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 logical name gnuplot$HELP should be defined as the name of the help library for `gnuplot`. The `gnuplot` help can be put inside any system help library, allowing access to help from both within and outside `gnuplot` if desired. 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 MS-DOS, if the BGI interface is used, 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 resolution and its mode of operation is Name.Mode. E.g., if the Super VGA driver is C:\TC\BGI\SVGADRV.BGI and mode 3 is used for 800x600 resolution, then use the following: set BGI=C:\TC\BGI set SVGA=SVGADRV.3 FIT_SCRIPT may be used to specify a `gnuplot` command to be executed when a fit is interrupted---see `fit`. FIT_LOG specifies the filename of the logfile maintained by fit. ?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 are expressed as {,}, 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. Note that gnuplot uses both "real" and "integer" arithmetic, like FORTRAN and C. Integers are entered as "1", "-10", etc; reals as "1.0", "-10.0", "1e1", 3.5e-1, etc. 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. In mixed expressions, integers are "promoted" to reals before evaluation: 5/2e0 = 2.5. The result of division of a negative integer by a positive one may vary among compilers. Try a test like "print -5/2" to determine if your system chooses -2 or -3 as the answer. The real and imaginary parts of complex expressions are always real, whatever the form in which they are entered: in {3,2} the "3" and "2" are reals, not integers. ?expressions functions ?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. For those functions that accept or return angles that may be given in either degrees or radians (sin(x), cos(x), tan(x), asin(x), acos(x), atan(x), atan2(x) and arg(z)), the unit may be selected by `set angles`, which defaults to radians. ?expressions functions abs ?functions abs ?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) ]. ?expressions functions acos ?functions acos ?acos The `acos` function returns the arc cosine (inverse cosine) of its argument. `acos` returns its argument in radians or degrees, as selected by `set angles`. ?expressions functions acosh ?functions acosh ?acosh The `acosh` function returns the inverse hyperbolic cosine of its argument in radians. ?expressions functions arg ?functions arg ?arg The `arg` function returns the phase of a complex number in radians or degrees, as selected by `set angles`. ?expressions functions asin ?functions asin ?asin The `asin` function returns the arc sin (inverse sin) of its argument. `asin` returns its argument in radians or degrees, as selected by `set angles`. ?expressions functions asinh ?functions asinh ?asinh The `asinh` function returns the inverse hyperbolic sin of its argument in radians. ?expressions functions atan ?functions atan ?atan The `atan` function returns the arc tangent (inverse tangent) of its argument. `atan` returns its argument in radians or degrees, as selected by `set angles`. ?expressions functions atan2 ?functions atan2 ?atan2 The `atan2` function returns the arc tangent (inverse tangent) of the ratio of the real parts of its arguments. `atan2` returns its argument in radians or degrees, as selected by `set angles`, in the correct quadrant. ?expressions functions atanh ?functions atanh ?atan The `atanh` function returns the inverse hyperbolic tangent of its argument in radians. ?expressions functions besj0 ?functions besj0 ?besj0 The `besj0` function returns the j0th Bessel function of its argument. `besj0` expects its argument to be in radians. ?expressions functions besj1 ?functions besj1 ?besj1 The `besj1` function returns the j1st Bessel function of its argument. `besj1` expects its argument to be in radians. ?expressions functions besy0 ?functions besy0 ?besy0 The `besy0` function returns the y0th Bessel function of its argument. `besy0` expects its argument to be in radians. ?expressions functions besy1 ?functions besy1 ?besy1 The `besy1` function returns the y1st Bessel function of its argument. `besy1` expects its argument to be in radians. ?expressions functions ceil ?functions ceil ?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. ?expressions functions cos ?functions cos ?cos The `cos` function returns the cosine of its argument. `cos` accepts its argument in radians or degrees, as selected by `set angles`. ?expressions functions cosh ?functions cosh ?cosh The `cosh` function returns the hyperbolic cosine of its argument. `cosh` expects its argument to be in radians. ?expressions functions erf ?functions erf ?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. ?expressions functions erfc ?functions erfc ?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. ?expressions functions exp ?functions exp ?exp The `exp` function returns the exponential function of its argument (`e` raised to the power of its argument). On some implementations (notably suns), exp(-x) returns undefined for very large x. A user-defined function like safe(x) = x<-100 ? 0 : exp(x) might prove useful in these cases. ?expressions functions floor ?functions floor ?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. ?expressions functions gamma ?functions gamma ?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. ?expressions functions ibeta ?functions ibeta ?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. ?expressions functions inverf ?functions inverf ?inverf The `inverf` function returns the inverse error function of the real part of its argument. ?expressions functions igamma ?functions igamma ?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. ?expressions functions imag ?functions imag ?imag The `imag` function returns the imaginary part of its argument as a real number. ?expressions functions invnorm ?functions invnorm ?invnorm The `invnorm` function returns the inverse normal distribution function of the real part of its argument. ?expressions functions int ?functions int ?int The `int` function returns the integer part of its argument, truncated toward zero. ?expressions functions lgamma ?functions lgamma ?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. ?expressions functions log ?functions log ?log The `log` function returns the natural logarithm (base `e`) of its argument. ?expressions functions log10 ?functions log10 ?log10 The `log10` function returns the logarithm (base 10) of its argument. ?expressions functions norm ?functions norm ?norm The `norm` function returns the normal distribution function (or Gaussian) of the real part of its argument. ?expressions functions rand ?functions rand ?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. ?expressions functions real ?functions real ?real The `real` function returns the real part of its argument. ?expressions functions sgn ?functions sgn ?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. ?expressions functions sin ?functions sin ?sin The `sin` function returns the sine of its argument. `sin` expects its argument to be in radians or degrees, as selected by `set angles`. ?expressions functions sinh ?functions sinh ?sinh The `sinh` function returns the hyperbolic sine of its argument. `sinh` expects its argument to be in radians. ?expressions functions sqrt ?functions sqrt ?sqrt The `sqrt` function returns the square root of its argument. ?expressions functions tan ?functions tan ?tan The `tan` function returns the tangent of its argument. `tan` expects its argument to be in radians or degrees, as selected by `set angles`. ?expressions functions tanh ?functions tanh ?tanh The `tanh` function returns the hyperbolic tangent of its argument. `tanh` expects its argument to be in radians. A few additional functions are also available. ?expressions functions column ?functions column ?column `column(x)` may be used only in expressions as part of `using` manipulations to fits or datafile plots. See `plot datafile using`. ?expressions tm_hour ?functions tm_hour The `tm_hour` function interprets its argument as a time, in seconds from 1 Jan 2000. It returns the hour (an integer in the range 0--23) as a real. ?expressions tm_mday ?functions tm_mday The `tm_mday` function interprets its argument as a time, in seconds from 1 Jan 2000. It returns the day of the month (an integer in the range 1--31) as a real. ?expressions tm_min ?functions tm_min The `tm_min` function interprets its argument as a time, in seconds from 1 Jan 2000. It returns the minute (an integer in the range 0--59) as a real. ?expressions tm_mon ?functions tm_mon The `tm_mon` function interprets its argument as a time, in seconds from 1 Jan 2000. It returns the month (an integer in the range 1--12) as a real. ?expressions tm_sec ?functions tm_sec The `tm_sec` function interprets its argument as a time, in seconds from 1 Jan 2000. It returns the second (an integer in the range 0--59) as a real. ?expressions tm_wday ?functions tm_wday The `tm_wday` function interprets its argument as a time, in seconds from 1 Jan 2000. It returns the day of the week (an integer in the range 1--7) as a real. ?expressions tm_yday ?functions tm_yday The `tm_yday` function interprets its argument as a time, in seconds from 1 Jan 2000. It returns the day of the year (an integer in the range 1--366) as a real. ?expressions tm_year ?functions tm_year The `tm_year` function interprets its argument as a time, in seconds from 1 Jan 2000. It returns the year (an integer) as a real. ?expressions functions valid ?functions valid ?valid `valid(x)` may be used only in expressions as part of `using` manipulations to fits or datafile plots. See `plot datafile using`. ?expressions operators ?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. ?expressions operators unary ?operators unary ?unary The following is a list of all the unary operators and their usages: Symbol Example Explanation - -a unary minus + +a unary plus (no-operation) ~ ~a * one's complement ! !a * logical negation ! a! * factorial $ $3 * call arg/column during `using` manipulation (*) Starred explanations indicate that the operator requires an integer argument. Operator precedence is the same as in Fortran and C. As in those languages, parantheses may be used to change the order of operation. Thus -2**2 = -4, but (-2)**2 = 4. The factorial operator returns a real number to allow a greater range. ?expressions operators binary ?operators binary ?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 a>b greater than >= a>=b greater than or equal to & a&b * bitwise AND ^ a^b * bitwise exclusive OR | a|b * bitwise inclusive OR && a&&b * logical AND || a||b * logical OR (*) 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. ?expressions operators ternary ?operators ternary ?ternary There is a single ternary operator: Symbol Example Explanation ?: a?b:c ternary operation The ternary operator behaves as it does in C. The first argument (a), which must be an integer, is evaluated. If it is true (non-zero), the second argument (b) is evaluated and returned; otherwise the third argument (c) is evaluated and returned. The ternary operator is very useful both in constructing piecewise functions and in plotting points only when certain conditions are met. Examples: Plot a function that is to equal sin(x) for 0 <= x < 1, 1/x for 1 <= x < 2, and undefined elsewhere: f(x) = 0<=x && x<1 ? sin(x) : 1<=x && x<2 ? 1/x : 1/0 plot f(x) Note that `gnuplot` quietly ignores undefined values, so the final branch of the function (1/0) will produce no plottable points. Note also that f(x) will be plotted as a continuous function across the discontinuity if a line style is used. To plot it discontinuously, create separate functions for the two pieces. (Parametric functions are also useful for this purpose.) For data in a file, plot the average of the data in columns 2 and 3 against the datum in column 1, but only if the datum in column 4 is non-negative: plot 'file' using 1:( $4<0 ? 1/0 : ($2+$3)/2 ) Please see `plot data-file using` for an explanation of the `using` syntax. ?expressions user-defined ?user-defined ?variables New user-defined variables and functions of one through five variables may be declared and used anywhere, including on the `plot` command itself. User-defined function syntax: ( {,} ... {,} ) = where is defined in terms of through . User-defined variable syntax: = Examples: w = 2 q = floor(tan(pi/2 - 0.1)) f(x) = sin(w*x) sinc(x) = sin(pi*x)/(pi*x) delta(t) = (t == 0) ramp(t) = (t > 0) ? t : 0 min(a,b) = (a < b) ? a : b comb(n,k) = n!/(k!*(n-k)!) len3d(x,y,z) = sqrt(x*x+y*y+z*z) plot f(x) = sin(x*a), a = 0.2, f(x), a = 0.4, f(x) Note that the variable `pi` is already defined. But it is in no way magic; you may redefine it to be whatever you like. Valid names are the same as in most programming languages: they must begin with a letter, but subsequent characters may be letters, digits, "$", or "_". Note, however, that the `fit` mechanism uses several variables with names that begin "FIT_". It is safest to avoid using such names. "FIT_LIMIT", however, is one that you may wish to redefine. See `show functions` and `show variables`. ?glossary Throughout this document an attempt has been made to maintain consistency of nomenclature. This cannot be wholly successful because as `gnuplot` has evolved over time, certain command and keyword names have been adopted that preclude such perfection. This section contains explanations of the way some of these terms are used. A "page" or "screen" is the entire area addressable by `gnuplot`. On a monitor, it is the full screen; on a plotter, it is a single sheet of paper. A screen may contain one or more "graphs". A graph is defined by an abscissa and an ordinate, although these need not actually appear on it. A graph may contain one or more "plots". A plot is a single function or data set. The plots on a graph may have individual names. These may be listed together with a sample of the line and/or point style used to represent them in the "key", sometimes also called the "legend". The word "title" occurs with multiple meanings in `gnuplot`. In this document, it will always be preceded by the adjective "graph", "plot", or "key" to differentiate among them. A graph may have up to four labelled axes. Various commands have the name of an axis built into their names, such as `set xlabel`. Other commands have one or more axis names as options, such as `set logscale xy`. The names of the four axes for these usages are "x" for the axis along the bottom border of the plot, "y" for the left border, "x2" for the top border, and "y2" for the right border. "z" also occurs in commands used with three-dimensional plotting. ?startup ?start ?.gnuplot When `gnuplot` is run, it looks for an initialization file to load. This file is called `.gnuplot` on Unix and AmigaDOS systems, and `GNUPLOT.INI` on other systems. If this file is not found in the current directory, the program will look for it in the home directory (under AmigaDOS, Atari(single)TOS, MS-DOS and OS/2, the environment variable `gnuplot` should contain the name of this directory). Note: if NOCWDRC is defined during the installation, `gnuplot` will not read from the current directory. If this file is found, `gnuplot` executes the commands in this file. This is most useful for setting the terminal type and defining any functions or variables that are used often. ?substitution Command-line substitution is specified by a system command enclosed in backquotes. This command is spawned and the output it produces replaces the name of the command (and backquotes) on the command line. Newlines in the output produced by the spawned command are replaced with blanks. Command-line substitution can be used anywhere on the `gnuplot` command line. Example: This will run the program `leastsq` and replace `leastsq` (including backquotes) on the command line with its output: f(x) = `leastsq` or, in VMS f(x) = `run leastsq` ?syntax ?specify ?punctuation The general rules of syntax and punctuation in `gnuplot` are that keywords and options are order-dependent. Options and any accompanying parameters are separated by spaces whereas lists and coordinates are separated by commas. Ranges are separated by colons and enclosed in braces [], text and file names are enclosed in quotes, and a few miscellaneous things are enclosed in parentheses. Brackets {} are used for a few special purposes. Commas are used to separate coordinates on the `set` commands `arrow`, `key`, and `label`; the list of variables being fitted (the list after the `via` keyword on the `fit` command); lists of discrete contours or the loop parameters which specify them on the `set cntrparam` command; the arguments of the `set` commands `dgrid3d`, `dummy`, `isosamples`, `offsets`, `origin`, `samples`, `size`, `time`, and `view`; lists of tics or the loop parameters which specify them; the offsets for titles and axis labels; parametric functions to be used to calculate the x, y, and z coordinates on the `plot`, `replot` and `splot` commands; and the complete sets of keywords specifying individual plots (data sets or functions) on the `plot`, `replot` and `splot` commands. Parentheses are used to delimit sets of explicit tics (as opposed to loop parameters) and to indicate computations in the `using` filter of the `fit`, `plot`, `replot` and `splot` commands. (Parentheses and commas are also used as usual in function notation.) Braces are used to delimit ranges, whether they are given on `set`, `plot` or `splot` commands. Colons are used to separate extrema in `range` specifications (whether they are given on `set`, `plot` or `splot` commands) and to separate entries in the `using` filter of the `plot`, `replot`, `splot` and `fit` commands. Semicolons are used to separate commands given on a single line. Brackets are used in text to be specially processed by some terminals, like `postscript`. They are also used to denote complex numbers: {3,2} = 3 + 2i. Text may be enclosed in single- or double-quotes. Backslash processing of sequences like \n (newline) and \345 (octal character code) is performed for double-quoted strings, but not for single-quoted strings. The justification is the same for each line of a multi-line string. Thus the center-justified string "This is the first line of text.\nThis is the second line." will produce This is the first line of text. This is the second line. but 'This is the first line of text.\nThis is the second line.' will produce This is the first line of text.\nThis is the second line. At present you should not embed \n inside {} when using the enhanced option of the postscript terminal. The EEPIC, Imagen, Uniplex, LaTeX, and TPIC drivers allow a newline to be specified by \\ in a single-quoted string or \\\\ in a double-quoted string. Back-quotes are used to enclose system commands for substitution. ?commands ?cd The `cd` command changes the working directory. Syntax: cd '' The directory name must be enclosed in quotes. Examples: cd 'subdir' cd ".." DOS users _must_ use single-quotes---backslash [\] has special significance inside double-quotes. For example, cd "c:\newdata" fails, but cd 'c:\newdata' works as expected. ?call The `call` command is identical to the load command with one exception: you can have up to ten 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 `call`ed 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 ten parameters on the `call` command line will cause an error. A parameter that was not provided substitutes as nothing. Files being `call`ed may themselves contain `call` or `load` commands. The `call` command _must_ be the last command on a multi-command line. Syntax: call "" ... The name of the input file must be enclosed in quotes, and it is recommended that parameters are similarly enclosed in quotes (future versions of gnuplot may treat quoted and unquoted arguments differently). Example: If the file 'calltest.gp' contains the line: print "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 NOTE: there is a clash in syntax with the datafile `using` callback operator. Use `$$n` or `column(n)` to access column n from a datafile inside a `call`ed datafile plot. ?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. For some terminals `clear` erases only the portion of the plotting surface defined by `set size`, so for these it can be used in conjunction with `set multiplot` to create an inset. Example: set multiplot plot sin(x) set origin 0.5,0.5 set size 0.4,0.4 clear plot cos(x) set nomultiplot Please see `set multiplot`, `set size`, and `set origin` for details of these commands. ?exit ?quit The commands `exit` and `quit` and the END-OF-FILE character will exit `gnuplot`. Each of these commands will clear the output device (as does the `clear` command) before exiting. ?fit This command provides the capability of nonlinear least squares fitting using the Marquardt-Levenberg Algorithm. It may fit any user-defined function of one or two independent variables to any set of data points (x,y) or (x,y,z). The function must depend on one or more parameters. Such a parameter can be any variable occurring in the function body (except for the independent variable(s), that is), or any additional function arguments. The goal of `fit` is to find a set of parameters that makes the function fit optimally to all the data points. Please see `fit introduction` if this description confused you. Syntax: fit {[xrange]} {[yrange]} '' {datafile-modifiers} via {'' | ,,...} [xrange] and [yrange] are of the form [{variable=}{}{:}], allowing the range of the fit to be limited temporarily in a manner analogous to `plot`. is any valid `gnuplot` expression, although it is usual to use a previously user-defined function of the form f(x) or f(x,y). is treated as in the `plot` command. All the modifiers for data files (`using`, `every`,...) in `plot` are available here (except `smooth`)---see `plot datafile` for full details. The default columns for x and y are 1 and 2. These may be changed by the `using x:y` mechanism. If `using` has a third entry (a column or an expression), it will be used as the standard deviation of each y value, or 'y-error' for short. This will be used to weight the y values and compute the errors in the final parameter values. See `fit errors` for further explanations. If four columns are specified, they are x:y:z:error. This is for fitting a function of _two_ variables x and y, to a 3-dimensional data set. It can also be used to fit a combination of multiple functions to a similar combine of data files, by using a pseudo column number of -1 or -2 instead of y (The fit demo contains an example of this kind). `fit` needs four columns to distinguish this from the previously described cases, so you will have to specify the default of `using ...:(1)` explicitly here, if no input data errors are available. The last item on the `fit` command line holds the list of parameters to fit, in one of two possible forms, both starting with the keyword `via`. The first form, `via 'filename'`, works by parsing the given file and reading lines of the following syntax from it: varname = value Comments, marked by '#', and blank lines are permissible. 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 way of specifying the adjustable parameters is to provide a comma-separated list of variable names after the `via` keyword. If any of these variables do not yet exist within the current `gnuplot` session, they are created with an initial value of 1.0, but the fit is more likely to converge if a more appropriate starting value is given. After each iteration step, a set of information about the state of the fit is written to the screen. The startup and final phases will additionally copy their screen output to a log file "fit.log". This file will never be erased but always appended to 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 MS-DOS and Atari Multitasking Systems). You then have the options of stopping (and accepting the current parameter values), continuing the iteration of the fit, or executing a `gnuplot` command specified by an environment variable FIT_SCRIPT. The default for FIT_SCRIPT is `replot`, so if you previously plotted both the data and the fit function in one graph, you'll see the current state of the fit. Special `gnuplot` variables: FIT_LIMIT may be specified to change the default epsilon limit (1e-5). When the sum of squared residuals changes between two iteration steps by less than a factor of this number, the fit is considered to have 'converged'. FIT_MAXITER may be specified to limit the number of iterations performed without convergence by FIT_LIMIT. A value of 0, or not defining it at all means there is no limit. This is mainly useful for unattended batch operation. In interactive operation, it's generally better to interrupt the fit manually, as described above. [FIT_SKIP was available in previous releases of gnufit. Its functionality is now obtained using the `every` modifier for data files. FIT_INDEX was previously available in order to allow multi-branch fitting. Multi-branch fitting in 2D (i.e. fitting a group of functions to a group of data sets, by combining them into a larger function and datafile, consisting of several branches) can now be done as a pseudo-3D fit in which the y values are the data line number (`using 1:-1:...`) or index (`using 1:-2:...`).] 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' via 'start.par' fit f(x) 'measured.dat' using 3:($7-5) via 'start.par' fit f(x) './data/trash.dat' using 1:2:3 via a, b, c fit f(x,y) 'surface.dat' using 1:2:3:(1) via a, b, c See also `update` ?fit introduction Beginner's guide to fitting in general `fit` is used to find a set of parameters to be used in a parametric function to make it fit to your data optimally. The quantity to be minimized is the sum of squared differences between your input data points and the function values at the same places, usually called 'chisquared' (i.e. the Greek letter chi, to the power of 2). (To be precise, the differences will be divided by the input data errors before being squared, see `fit errors` for details.) Now you know why it's called 'least squares fitting', let's see why it's 'nonlinear'. That's because the function's dependence on the parameters (not the data!) may be non-linear. Of course, this might not tell you much if you didn't know already, so let me try to describe it. If the fitting problem were to be linear, the target function would have to be a sum of simple, non-parametric functions, each multiplied by one parameter. For such a linear case, the task of fitting can be performed by comparatively simple linear algebra, in one direct step. But `fit` can to more for you: the parameters may be used in your function in every way you can imagine. To handle this more general case, however, it has to perform an iteration, i.e. it will repeat a sequence of steps until it finds the fit to have 'converged', or until you stop it. Generally, the function to be fitted will come from some kind of theory (some prefer the term 'model' here) that makes a prediction about how the data should behave, and `fit` is then used to find the free parameters of the theory. This is a typical task in scientific work, where you have lots of data that depend in more or less complicated way on the values you're interested in. The results will then usually be of the form 'the measured data can be described by the {foo} theory, for the following set of parameters', and then a set of values is given, together with the errors of your determination of these values. This reasoning implies that `fit` is probably _not_ your tool of choice if all you really want is a smooth line through your data points. If you want this, the `smooth` option to `plot` is what you've been looking for, not `fit`. ?fit errors One of the most important things to keep in mind when using `fit` is the handling of errors. Here, this term refers to the measurement errors accompanying both your input data and resulting parameters. The reason for the importance of input data errors to fitting is that normally the single measurements aren't all of the same quality, so they shouldn't have the same importance in determining the results. That's one major reason for dividing the differences between data and function by the input errors, also known as 'weighting', in the computation of chisquared. By weighting, deviations from your function at places where the data have large errors will have a smaller part in chisquared, as the division will make them smaller compared to the better measurements. Another reason for the division is that, for mathematical reasons, chisquared has to be a dimensionless variable, i.e. chisquared should be something like '15.3', not '15.3 square seconds'. Without input data errors being given, all data will be weighted equally, and the resulting errors of the parameters won't have much of a real meaning. Therefore, you should always try to find a sensible set of y-errors for your data. An important example is that of data representing a histogram. In such a case, the square root of the y value is often the correct input error to use Once the fit iteration has stopped, it will display a load of valuable info, which you will have to learn to interpret before you can use it. The 'sum of squares residuals' is the distance between the data and your fit function, shortly called 'chisquared'. This is what `fit` tries to minimize. To quickly test if your fit went well, check that this is about the same as the number of data points minus the number of parameters (all this is only valid if you supplied y-errors, and the number of data points is high enough). For details on this, look up the 'Chi-squared distribution' in your favourite statistics textbook. If chisquared is much larger than that, then your function didn't fit the data very well. Try another, more general one, or allow more of the parameters to be adjusted by `fit`. Another possible reason could be that the y-errors you supplied were a bit optimistic, i.e. too small. If, on the other hand, chisquared is too small, then the function fit the data _too_ well. Either the given y-errors were too large, or the function is too general. You should try to restrict it by either fixing some parameters, or just make it simpler one way or the other. If all else went well, you'll see a list of the resulting parameter values, together with estimates of the errors of these values. And you should always be aware of this: they're _estimates_, not more. You'll have to get used to both `fit` and your usual kind of problems you apply it to before you can use these errors for anything serious. To start with, the errors reported by `fit` are insensitive to the global scale of the y-errors, i.e. if you multiply all y-errors by a constant, the resulting parameter errors don't change. And, to repeat this once more: if you didn't supply y-errors, the parameter errors will normally be meaningless. ?fit tips Here are some tips to keep in mind to get the most out of `fit`. They're not very organized, so you'll have to read them several times until the essence of it has sunk in. The two forms of the `via` argument to fit serve to largely distinct purposes. The `via "file"` form is best used for, possibly unattended, batch operation, where you just supply the startup values in a file and can later use `update` to copy the results back into another, or the same one. The `via var1, var2, ...` form is best used interactively. Using the command history mechanism built into gnuplot, you can easily edit the list of parameters to be fitted, or supply new startup values for the next try. This is particularly useful for hard problems, where a direct fit to all parameters at once won't work, at least not without really _good_ values to start with. To find such a set of good starting parameters, you can iterate several times, fitting only some of the parameters, until the values are close enough to the goal so that the final fit to all parameters at once will work. A general word about starting values: `fit` may, and often will get really badly lost in searching for the optimal parameter set if you start it way off any possible solution. The main reason for this is that nonlinear fitting is not guaranteed to converge to a global optimum. It can get stuck in a local optimum, and there's no way for the routine to find out about that. You'll have to use your own judgement in checking whether this has happened to your or not. To partly avoid that problem, you should put all starting values at least roughly into the vicinity of the solution. At least the order of magnitude should be correct, if possible. The better your starting values are, the less error-prone the fit. A good way to find starting values is to draw data and fit-function into one plot, and iterate in changing the values and `replot`-ting until reasonable similarity is reached. The same plot is also useful to check if the fit got stuck in a non-global minimum. Make sure that there is no mutual dependency among parameters of the function you are fitting. E.g., don't try to fit a*exp(x+b), because a*exp(x+b)=a*exp(b)*exp(x). Instead, fit either a*exp(x) or exp(x+b). A technical issue: the parameters must not be too different in magnitude. The larger the quotient of the largest and the smallest absolute parameter values, the slower the fit will converge. If the quotient is close to or above the inverse of the machine floating point precision, it may take next to forever to converge, or refuse to converge at all. You'll have to adapt your function to avoid this, e.g. replace 'parameter' by '1e9*parameter' in the function definition, and divide the starting value by 1e9. If you can write your function as a linear combination of simple functions weighted by the parameters to be fitted, by all means do so. That helps a lot, because the problem is then not nonlinear any more. It should take only a really small number of iterations to converge on a linear case, maybe even only one. In prescriptions for analysing data from practical experimentation courses, you'll often find descriptions how to first fit your data to some functions, maybe in a multi-step process of accounting for several aspects of the underlying theory one by one, and then extract the data you really wanted from the fitting parameters of that function. With `fit`, this last step can often be eliminated by rewriting the model function to directly use the desired final parameters. Transforming data can also be avoided quite often, although sometimes at the cost of a harder fit problem. If you think this contradicts the previous paragraph about keeping the fit function a simple as possible, you're correct. Finally, a nice quote from the manual of another fitting package (fudgit), that kind of summarizes all these issues: "Nonlinear fitting is an art!" ?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, a menu of subtopics 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 you may go back one level to the previous topic. Eventually, the `gnuplot` command line will return. If a question mark (?) is given as the topic, the list of topics currently available is printed on the screen. ?if The `if` command allows commands to be executed conditionally. Syntax: if () will be evaluated. If it is true (non-zero), then the command(s) of the will be executed. If is false (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)) print "?Fixing pi!"; pi=acos(-1); print pi will display: ?Fixing pi! 3.14159265358979 but if (1==2) print "Never see this"; print "Or this either" will not display anything. See `reread` for an example of how `if` and `reread` can be used together to perform a loop. ?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 `load`ed. Any text file containing valid commands can be created and then executed by the `load` command. Files being `load`ed may themselves contain `load` or `call` commands. See `comment` for information about comments in commands. The `load` command _must_ be the last command on a multi-command 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. See also `call`. ?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