Mailing list for comments: info-gnuplot@dartmouth.edu
Mailing list for bug reports: bug-gnuplot@dartmouth.edu
gnuplot
Commands
Graphical User Interfaces
Bugs
Copyright
Introduction
Seeking-assistance
What's New in version 3.6
Command-line-editing
Comments
Coordinates
Environment
Expressions
Glossary
Plotting
Start-up
Substitution
Syntax
Time/Date data
Copyright (C) 1986 - 1993, 1997 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.
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). Simple Plots Demo
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.
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 Marquardt-Levenberg method to fit data. (This is only slightly different from the gnufit patch available for 3.5.)
2. Greatly expanded using command. See plot using.
3. set timefmt allows for the use of dates as input and output for time series plots. See Time/Date data and 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. See set key.
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 can try 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. Furthermore these types may be combined and stored for further use. See set linestyle.
26. Text (labels, tic labels, and the time stamp) can be written vertically by those terminals capable of doing so.
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 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.
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:
{<system>} <x>, {<system>} <y> {,{<system>} <z>}
Each <system> 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.
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.
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 {<real>,<imag>}, where <real> and <imag> 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.
Functions
Operators
User-defined
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.
abs
acos
acosh
arg
asin
asinh
atan
atan2
atanh
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
column
tm_hour
tm_mday
tm_min
tm_mon
tm_sec
tm_wday
tm_yday
tm_year
valid
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) ].
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.
The acosh function returns the inverse hyperbolic cosine of its argument in radians.
The arg function returns the phase of a complex number in radians or degrees, as selected by set angles.
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.
The asinh function returns the inverse hyperbolic sin of its argument in radians.
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.
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.
The atanh function returns the inverse hyperbolic tangent of its argument in radians.
The besj0 function returns the j0th Bessel function of its argument. besj0 expects its argument to be in radians.
The besj1 function returns the j1st Bessel function of its argument. besj1 expects its argument to be in radians.
The besy0 function returns the y0th Bessel function of its argument. besy0 expects its argument to be in radians.
The besy1 function returns the y1st Bessel function of its argument. besy1 expects its argument to be in radians.
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.
The cos function returns the cosine of its argument. cos accepts its argument in radians or degrees, as selected by set angles.
The cosh function returns the hyperbolic cosine of its argument. cosh expects its argument to be in radians.
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.
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.
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.
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.
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.
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.
The inverf function returns the inverse error function of the real part of its argument.
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.
The imag function returns the imaginary part of its argument as a real number.
The invnorm function returns the inverse normal distribution function of the real part of its argument.
The int function returns the integer part of its argument, truncated toward zero.
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.
The log function returns the natural logarithm (base e) of its argument.
The log10 function returns the logarithm (base 10) of its argument.
The norm function returns the normal distribution function (or Gaussian) of the real part of its argument.
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.
The real function returns the real part of its argument.
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.
The sin function returns the sine of its argument. sin expects its argument to be in radians or degrees, as selected by set angles.
The sinh function returns the hyperbolic sine of its argument. sinh expects its argument to be in radians.
The sqrt function returns the square root of its argument.
The tan function returns the tangent of its argument. tan expects its argument to be in radians or degrees, as selected by set angles.
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.
column(x) may be used only in expressions as part of using manipulations to fits or datafile plots. See plot datafile using.
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.
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.
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.
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.
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.
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.
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.
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.
valid(x) may be used only in expressions as part of using manipulations to fits or datafile plots. See plot datafile using. Use of functions and complex variables for airfoils
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.
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, parentheses 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.
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 less than
<= a<=b less than or equal to
> 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.
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.
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:
<func-name>( <dummy1> {,<dummy2>} ... {,<dummy5>} ) = <expression>
where <expression> is defined in terms of <dummy1> through <dummy5>.
User-defined variable syntax:
<variable-name> = <constant-expression>
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.
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 "plots". A plot is defined by an abscissa and an ordinate, although these need not actually appear on it, as well as the margins and any text written therein.
A plot contains one "graph". 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 "lines". A line is a single function or data set. "Line" is also a plotting style. The word will also be used in sense "a line of text". Presumably the context will always remove the ambiguity.
The lines on a graph may have individual names. These may be listed together with a sample of the plotting 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 "plot", "line", 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 3-d plotting.
When discussing data files, the term "record" will be resurrected and used to denote a single line in the file, that is, the characters between newline or end-of-record characters. A "point" is the datum on a single record, and a "dataline" is a set of points on consecutive records, delimited by blank records.
There are three gnuplot commands which actually create a plot: plot, splot and replot. plot generates 2-d plots, splot generates 3-d plots (actually 2-d projections, of course), and replot appends its arguments to the previous plot or splot and executes the modified command.
Much of the general information about plotting can be found in the discussion of plot; information specific to 3-d can be found in the splot section.
plot operates in either rectangular or polar coordinates -- see set polar for details of the latter. splot operates only in rectangular coordinates, but the set mapping command allows for a few other coordinate systems to be treated. In addition, the using option allows both plot and splot to treat almost any coordinate system you'd care to define.
splot can plot surfaces and contours in addition to lines. See splot datafile for information about the requisite file structure for both of these; see set isosamples for information about defining the grid for a 3-d function. See set contour and set cntrparam for information about contours.
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 the initialization file is found, gnuplot executes the commands in it. These may be any legal gnuplot commands, but typically they are limited to setting the terminal and defining frequently-used functions or variables.
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
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 command 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.
gnuplot supports the use of time and/or date information as input data. This feature is activated by the commands set xdata time, set ydata time, etc.
Internally all times and dates are converted to the number of seconds from the year 2000. The command set timefmt defines the format for all inputs: data files, ranges, tics, label positions---in short, anything that accepts a data value must receive it in this format. Since only one input format can be in force at a given time, all time/date quantities being input at the same time must be presented in the same format. Thus if both x and y data in a file are time/date, they must be in the same format.
Commands like show xrange will re-interpret the integer according to timefmt. If you change timefmt, and then show the quantity again, it will be displayed in the new timefmt. For that matter, if you give the deactivation command (like set xdata), the quantity will be shown in its numerical form.
The command set format defines the format that will be used for tic labels, whether or not the specified axis is time/date.
If time/date information is to be plotted from a file, the using option _must_ be used on the plot or splot command. These commands simply use white space to separate columns, but white space may be embedded within the time/date string. If you use tabs as a separator, some trial-and-error may be necessary to discover how your system treats them.
The following example demonstrates time/date plotting.
Suppose the file "data" contains records like
03/21/95 10:00 6.02e23
This file can be plotted by
set xdata time
set timefmt "%m/%d"
set xrange ["03/21":"03/22"]
set format x "%m/%d"
set timefmt "%m/%d/%y %H:%M"
plot "data" using 1:3
which will produce xtic labels that look like "03/21".
See the descriptions of each command for more details.
cd
call
clear
exit
fit
help
if
load
pause
plot
print
pwd
quit
replot
reread
reset
save
set-show
shell
splot
test
update
The cd command changes the working directory.
Syntax:
cd '<directory-name>'
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.
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 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 ten 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 a multi-command line.
Syntax:
call "<input-file>" <parameter-0> <parm-1> ... <parm-9>
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 called datafile plot.
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.
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.
This implementation incorporates the capability of nonlinear least squares fitting using the Marquardt-Levenberg Algorithm. It may fit any user-defined function to any set of data points (x,y) or (x,y,z). x, y, z and the function's return type _must_ be real! Any variable occurring in the function body may serve as a fit parameter (fitting functions without adjustable parameters make no sense).
Syntax:
fit {[xrange]} {[yrange]} <function>
'<datafile>' {datafile-modifiers}
via {'<parameter file>' | <var1>,<var2>,...}
Notice that via is now a required keyword, to distinguish it from a 'scanf' format string.
[xrange] and [yrange] are of the form [{variable=}{<min>}{:<max>}], allowing the range of the fit to be limited temporarily in a manner analogous to plot. <function> 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). <datafile> is treated as in the plot command. All the modifiers for datafiles (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 interpreted as the standard deviation of each y value and will be used to compute the weight; otherwise all data will be weighted equally. If four columns are specified, they are x:y:z:error---note that an error _must_ be specified in order to perform a 3-d fit. If errors are not available, a constant value can be specified, e.g., using ...:(1).
Initial values for the parameters to be fit may be specified in a (load-)file wherein each line is of the form:
varname = value
Comments, marked by '#', and blank lines are permissible. The special 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 means 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. If this form is used, it may prove beneficial to iterate the fit, allowing only one or two variables to be adjusted at a time until a reasonably close fit is obtained, before allowing fit to vary all parameters.
After each iteration step, detailed information 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 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 MSDOS and Atari Multitasking Systems). Then you 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. A plot or load command may be useful in this context.
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'.
Once the fit is converged, the final values may be stored in (load-)file suitable for use as an initial-value file, as discussed above. Please see update for details.
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 that there is no limit.
[FIT_SKIP was available in previous releases of gnufit. Its functionality is now obtained using the every modifier for datafiles. FIT_INDEX was previously available in order to allow multi-branch fitting. Multi-branch fitting in 2-d can now be done as a pseudo-3-d fit in which the y values are the dataline 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_LIMIT = 1e-6
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 the `fit` demos.
Introduction To Fitting
Errors In Fitting
Tips and Tricks
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 that 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 example, consider the function f(x) = c*sin(x), where we want to find the best value for the constant c. This is nonlinear in x, of course, but it is linear in c. Since the fitting procedure solves for c, it has a linear equation to solve.) For such a linear case, the task of fitting can be performed by comparatively simple linear algebra in one direct step. But fit can do more for you: the parameters may be used in your function in any 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 ways 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. See plot datafile smooth for details.
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 information 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 large 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 kind of problems you usually 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.
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 their essence has sunk in.
The two forms of the via argument to fit serve two largely distinct purposes. The via "file" form is best used for batch operation (possibly unattended), where you just supply the startup values in a file and perhaps later use update to copy the results back into another file (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 the 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 each time, until the values are close enough to the goal that the final fit (to all the 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 you 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, 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 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 as 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!"
The help command displays on-line help. To specify information on a particular topic use the syntax:
help {<topic>}
If <topic> 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.
The if command allows commands to be executed conditionally.
Syntax:
if (<condition>) <command-line>
<condition> will be evaluated. If it is true (non-zero), then the command(s) of the <command-line> will be executed. If <condition> is false (zero), then the entire <command-line> 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.
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 a multi-command line.
Syntax:
load "<input-file>"
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.
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 <time> {"<string>"}
<time> may be any integer constant or expression. Choosing -1 will wait until a carriage return is hit, zero (0) won't pause at all, and a positive integer will wait the specified number of seconds. pause 0 is synonymous with print.
Note: Since pause communicates with the operating system rather than the graphics, it may behave differently with different device drivers (depending upon how text and graphics are mixed).
Examples:
pause -1 # Wait until a carriage return is hit
pause 3 # Wait three seconds
pause -1 "Hit return to continue"
pause 10 "Isn't this pretty? It's a cubic spline."
plot is the primary command for drawing plots with gnuplot. It creates plots of functions and data in many, many ways. plot is used to draw 2-d functions and data; splot draws 2-d projections of 3-d surfaces and data. plot and splot contain many common features; see splot for differences.
Syntax:
plot {<ranges>}
{<function> | {"<datafile>" {datafile-modifiers}}}
{axes <axes>} {<title-spec>} {with <style>}
{, {definitions,} <function> ...}
where either a <function> or the name of a data file enclosed in quotes is supplied. A function is a mathematical expression or a pair of mathematical expressions in parametric mode. The expressions may be defined completely or in part earlier in the stream of gnuplot commands (see user-defined).
It is also possible to define functions and parameters on the plot command itself. This is done merely by isolating them from other items with commas.
There are four possible sets of axes available; the keyword <axes> is used to select the axes for which a particular line should be scaled. x1y1 refers to the axes on the bottom and left; x2y2 to those on the top and right; x1y2 to those on the bottom and right; and x2y1 to those on the top and left. Ranges specified on the plot command apply only to the first set of axes (bottom left).
Examples:
plot sin(x)
plot f(x) = sin(x*a), a = .2, f(x), a = .4, f(x)
plot [t=1:10] [-pi:pi*2] tan(t), \
"data.1" using (tan($2)):($3/$4) smooth csplines \
axes x1y2 notitle with lines 5
data-file
errorbars
parametric
ranges
title
with
Discrete data contained in a file can be displayed by specifying the name of the data file (enclosed in quotes) on the plot or splot command line.
Syntax:
{s}plot '<file_name>' {rdb}
{index <index list>}
{every <every list>}
{thru <thru expression>}
{using <using list>}
{smooth <option>}
The modifiers rdb, index, every, thru, using, and smooth are discussed separately. In brief, rdb reads rdb format files, index selects which data sets in a multi-data-set file are to be plotted, every specifies which points within a single data set are to be plotted, using determines how the columns within a single record are to be interpreted (thru is a special case of using), and smooth allows for simple interpolation and approximation.
Data files should contain one data point per record. Records beginning with # (or ! on VMS) will be treated as comments and ignored. Each data point represents an (x,y) pair. For plots with error bars (see set style errorbars), each data point is (x,y,ydelta), (x,y,ylow,yhigh), (x,y,xdelta), (x,y,xlow,xhigh), or (x,y,xlow,xhigh,ylow,yhigh). In all cases, the numbers on each record of a data file must be separated by white space (one or more blanks or tabs), unless a format specifier is provided by the using option. This white space divides each record into columns.
Data may be written in exponential format with the exponent preceded by the letter e, E, d, D, q, or Q.
Only one column (the y value) need be provided. If x is omitted, gnuplot provides integer values starting at 0.
In datafiles, blank records (records with no characters other than blanks and a newline and/or carriage return) are significant---pairs of blank records separate indexes (see plot datafile index). Data separated by double blank records are treated as if they were in separate data files.
Single blank records designate discontinuities in a plot; no line will join points separated by a blank records (if they are plotted with a line style).
If autoscaling has been enabled (set autoscale), the axes are automatically extended to include all datapoints, with a whole number of tic marks if tics are being drawn. This has two consequences: i) For splot, the corner of the surface may not coincide with the corner of the base. In this case, no vertical line is drawn. ii) When plotting data with the same x range on a dual-axis graph, the x coordinates may not coincide if the x2tics are not being drawn. This is because the x axis has been autoextended to a whole number of tics, but the x2 axis has not. The following example illustrates the problem:
reset; plot '-', '-'
1 1
19 19
e
1 1
19 19
e
every
example datafile
rdb
index
smooth
special-filenames
thru
using
The every keyword allows a periodic sampling of a data set to be plotted.
In the discussion a "point" is a datum defined by a single record in the file.
Syntax:
plot 'file' every {<point_incr>}
{:{<line_incr>}
{:{<start_point>}
{:{<start_line>}
{:{<end_point>}
{:<end_line>}}}}}
The data points to be plotted are selected according to a loop from <start_point> to <end_point> with increment <point_incr> and the datalines according to a loop from <start_line> to <end_line> with increment <line_incr>.
The first datum in each dataline is numbered '0', as is the first dataline in the file.
Note that records containing unplottable information are counted.
Any of the numbers can be omitted; the increments default to unity, the start values to the first point or dataline, and the end values to the last point or dataline. If every is not specified, all points in all datalines are plotted.
Examples:
every :::3::3 # selects just the fourth dataline ('0' is first)
every :::::9 # selects the first 10 datalines
every 2:2 # selects every other point in every other dataline
every ::5::15 # selects points 5 through 15 in each dataline
Simple Plot Demos ,
Non-parametric splot demos , and
Parametric splot demos.
This example compares the data in the file population.dat to a theoretical curve:
pop(x) = 103*exp((1965-x)/10)
plot [1960:1990] 'population.dat', pop(x)
The file "population.dat" might contain:
# Gnu population in Antarctica since 1965
1965 103
1970 55
1975 34
1980 24
1985 10
The rdb keyword specifies that the file is in the RDB format. An RDB file is a ascii text relational database consisting of comment lines beginning with # and two header lines. The first with column names and the second with a column width and type. Columns are tab-seperated. This option causes the two header lines to be skiped.
The index keyword allows only some of the data sets in a multi-data-set file to be plotted.
Syntax:
plot 'file' index <m>{{:<n>}:<p>}
Data sets are separated by pairs of blank records. index <m> selects only set <m>; index <m>:<n> selects sets in the range <m> to <n>; and index <m>:<n>:<p> selects indices <m>, <m>+<p>, <m>+2<p>, etc., but stopping at <n>. Following C indexing, the index 0 is assigned to the first data set in the file. Specifying too large an index results in an error message. If index is not specified, all sets are plotted as a single data set.
Example:
plot 'file' index 4:5
splot with indices demo.
gnuplot includes a few general-purpose routines for interpolation and approximation of data; these are grouped under the smooth option. More sophisticated data processing may be performed by preprocessing the data externally or by using fit with an appropriate model.
Syntax:
smooth {unique | csplines | acsplines | bezier | sbezier}
unique plots the data after making them monotonic. Each of the other routines uses the data to determine the coefficients of a continuous curve between the endpoints of the data. This curve is then plotted in the same manner as a function, that is, by finding its value at uniform intervals along the abscissa (see set samples) and connecting these points with straight line segments (if a line style is chosen).
If autoscale is in effect, the ranges will be computed such that the plotted curve lies within the borders of the graph.
If too few points are available to allow the selected option to be applied, an error message is produced. The minimum number is one for unique, four for acsplines, and three for the others.
The smooth options have no effect on function plots.
acsplines
bezier
csplines
sbezier
unique
acsplines approximates the data with a "natural smoothing spline". After the data are made monotonic in x (see smooth unique), a curve is piecewise constructed from segments of cubic polynomials whose coefficients are found by the weighting the data points; the weights are taken from the third column in the data file. That default can be modified by the third entry in the using list, e.g.,
plot 'data-file' using 1:2:(1.0) smooth acsplines
Qualitatively, the absolute magnitude of the weights determines the number of segments used to construct the curve. If the weights are large, the effect of each datum is large and the curve approaches that produced by connecting consecutive points with natural cubic splines. If the weights are small, the curve is composed of fewer segments and thus is smoother; the limiting case is the single segment produced by a weighted linear least squares fit to all the data. The smoothing weight can be expressed in terms of errors as a statistical weight for a point divided by a "smoothing factor" for the curve so that (standard) errors in the file can be used as smoothing weights.
Example:
sw(x,S)=1/(x*x*S)
plot 'data_file' using 1:2:(sw($3,100)) smooth acsplines
The bezier option approximates the data with a Bezier curve of degree n (the number of data points) that connects the endpoints.
The csplines option connects consecutive points by natural cubic splines after rendering the data monotonic (see smooth unique).
The sbezier option first renders the data monotonic (unique) and then applies the bezier algorithm.
The unique option makes the data monotonic in x; points with the same x-value are replaced by a single point having the average y-value. The resulting points are then connected by straight line segments. See demos.
A special filename of '-' specifies that the data are inline; i.e., they follow the command. Only the data follow the command; plot options like filters, titles, and line styles remain on the 'plot' command line. This is similar to << in unix shell script, and $DECK in VMS DCL. The data are entered as though they are being read from a file, one data point per record. The letter "e" at the start of the first column terminates data entry. The using option can be applied to these data---using it to filter them through a function might make sense, but selecting columns probably doesn't!
'-' is intended for situations where it is useful to have data and commands together, e.g., when gnuplot is run as a sub-process of some front-end application. Some of the demos, for example, might use this feature. While plot options such as index and every are recognized, their use forces you to enter data that won't be used. For example, while
plot '-' index 0, '-' index 1
2
4
6
10
12
14
e
2
4
6
10
12
14
e
does indeed work,
plot '-', '-'
2
4
6
e
10
12
14
e
is a lot easier to type.
If you use '-' with replot, you may need to enter the data more than once (see replot).
A blank filename ('') specifies that the previous filename should be reused. This can be useful with things like
plot 'a/very/long/filename' using 1:2, '' using 1:3, '' using 1:4
(If you use both '-' and '' on the same plot command, you'll need to have two sets of inline data, as in the example above.)
On some computer systems with a popen function (Unix), the datafile can be piped through a shell command by starting the file name with a '<'. For example,
pop(x) = 103*exp(-x/10)
plot "< awk '{print $1-1965, $2}' population.dat", pop(x)
would plot the same information as the first population example but with years since 1965 as the x axis. If you want to execute this example, you have to delete all comments from the data file above or substitute the following command for the first part of the command above (the part up to the comma):
plot "< awk '$0 !~ /^#/ {print $1-1965, $2}' population.dat"
While this approach is most flexible, it is possible to achieve simple filtering with the using or thru keywords.
The thru function is provided for backward compatibility.
Syntax:
plot 'file' thru f(x)
It is equivalent to:
plot 'file' using 1:(f($2))
While the latter appears more complex, it is much more flexible. The more natural
plot 'file' thru f(y)
also works (i.e. you can use y as the dummy variable).
thru is parsed for splot and fit but has no effect.
The most common datafile modifier is using.
Syntax:
plot 'file' using {<entry> {:<entry> {:<entry> ...}}} {'format'}
If a format is specified, each datafile record is read using the C library's 'scanf' function, with the specified format string. Otherwise the record is read and broken into columns at spaces or tabs. A format cannot be specified if time-format data is being used (this must be done by set data time).
The resulting array of data is then sorted into columns according to the entries. Each <entry> may be a simple column number, which selects the datum, an expression enclosed in parentheses, or empty. The expression can use $1 to access the first item read, $2 for the second item, and so on. It can also use column(x) and valid(x) where x is an arbitrary expression resulting in an integer. column(x) returns the x'th datum; valid(x) tests that the datum in the x'th column is a valid number. A column number of 0 generates a number increasing (from zero) with each point, and is reset upon encountering two blank records. A column number of -1 gives the dataline number, which starts at 0, increments at single blank records, and is reset at double blank records. A column number of -2 gives the index number, which is incremented only when two blank records are found. An empty <entry> will default to its order in the list of entries. For example, using ::4 is interpreted as using 1:2:4.
N.B.---the call command also uses $'s as a special character. See call for details about how to include a column number in a call argument list.
If the using list has but a single entry, that <entry> will be used for y and the data point number is used for x; for example, "plot 'file' using 1" is identical to "plot 'file' using 0:1". If the using list has two entries, these will be used for x and y. Additional entries are usually errors in x and/or y. See set style for details about plotting styles that make use of error information, and fit for use of error information in curve fitting.
'scanf' accepts several numerical specifications but gnuplot requires all inputs to be double-precision floating-point variables, so lf is the only permissible specifier. 'scanf' expects to see white space---a blank, tab ("\t"), newline ("\n"), or formfeed ("\f")---between numbers; anything else in the input stream must be explicitly skipped.
Note that the use of "\t", "\n", or "\f" or requires use of double-quotes rather than single-quotes.
Examples:
This creates a plot of the sum of the 2nd and 3rd data against the first: (The format string specifies comma- rather than space-separated columns.)
plot 'file' using 1:($2+$3) '%lf,%lf,%lf'
In this example the data are read from the file "MyData" using a more complicated format:
plot "MyData" using "%*lf%lf%*20[^\n]%lf"
The meaning of this format is:
%*lf ignore a number
%lf read a double-precision number (x by default)
%*20[^\n] ignore 20 non-newline characters
%lf read a double-precision number (y by default)
One trick is to use the ternary ?: operator to filter data:
plot 'file' using 1:($3>10 ? $2 : 1/0)
which plots the datum in column two against that in column one provided the datum in column three exceeds ten. 1/0 is undefined; gnuplot quietly ignores undefined points, so unsuitable points are suppressed.
In fact, you can use a constant expression for the column number, provided it doesn't start with an opening parenthesis; constructs like using 0+(complicated expression) can be used. The crucial point is that the expression is evaluated once if it doesn't start with a left parenthesis, or once for each data point read if it does.
If timeseries data are being used, the time can span multiple columns. The starting column should be specified. Note that the spaces within the time must be included when calculating starting columns for other data. E.g., if the first element on a line is a time with an embedded space, the y value should be specified as column three.
It should be noted that plot 'file', plot 'file' using 1:2, and plot 'file' using ($1):($2) can be subtly different: 1) if file has some lines with one column and some with two, the first will invent x values when they are missing, the second will quietly ignore the lines with one column, and the third will store an undefined value for lines with one point (so that in a plot with lines, no line joins points across the bad point); 2) if a line contains text at the first column, the first will abort the plot on an error, but the second and third should quietly skip the garbage.
In fact, it is often possible to plot a file with lots of lines of garbage at the top simply by specifying
plot 'file' using 1:2
If you want to leave text in your data files, it is always safe to put the comment character (#) in the first column of the text lines. Feeble using demos.
Error bars are supported for 2-d data file plots by reading one to four additional columns (or using entries); these additional values are used in different ways by the various errorbar styles.
In the default situation, gnuplot expects to see three, four, or six numbers on each line of the data file---either
(x, y, ydelta),
(x, y, ylow, yhigh),
(x, y, xdelta),
(x, y, xlow, xhigh),
(x, y, xdelta, ydelta), or
(x, y, xlow, xhigh, ylow, yhigh).
The x coordinate must be specified. The order of the numbers must be exactly as given above, though the using qualifier can manipulate the order and provide values for missing columns. For example,
plot 'file' with errorbars
plot 'file' using 1:2:(sqrt($1)) with xerrorbars
plot 'file' using 1:2:($1-$3):($1+$3):4:5 with xyerrorbars
The last example is for a file containing an unsupported combination of relative x and absolute y errors. The using entry generates absolute x min and max from the relative error.
The y error bar is a vertical line plotted from (x, ylow) to (x, yhigh). If ydelta is specified instead of ylow and yhigh, ylow = y - ydelta and yhigh = y + ydelta are derived. If there are only two numbers on the record, yhigh and ylow are both set to y. The x error bar is a horizontal line computed in the same fashion. To get lines plotted between the data points, plot the data file twice, once with errorbars and once with lines (but remember to use the notitle option on one to avoid two entries in the key).
The error bars have crossbars at each end unless set bar is used (see set bar for details).
If autoscaling is on, the ranges will be adjusted to include the error bars. Errorbar demos.
See plot using, plot with, and set style for more information.
When in parametric mode (set parametric) mathematical expressions must be given in pairs for plot and in triplets for splot.
Examples:
plot sin(t),t**2
splot cos(u)*cos(v),cos(u)*sin(v),sin(u)
Data files are plotted as before, except any preceding parametric function must be fully specified before a data file is given as a plot. In other words, the x parametric function (sin(t) above) and the y parametric function (t**2 above) must not be interrupted with any modifiers or data functions; doing so will generate a syntax error stating that the parametric function is not fully specified.
Other modifiers, such as with and title, may be specified only after the parametric function has been completed:
plot sin(t),t**2 title 'Parametric example' with linespoints
Parametric Mode Demos.
The optional ranges specify the region of the graph that will be displayed.
Syntax:
[{<dummy-var>=}{{<min>}:{<max>}}]
[{{<min>}:{<max>}}]
The first form applies to the independent variable (xrange or trange, if in parametric mode). The second form applies to the dependent variable yrange (and xrange, too, if in parametric mode). <dummy-var> is a new name for the independent variable. (The defaults may be changed with set dummy.) The optional <min> and <max> terms can be constant expressions or *.
In non-parametric mode, the order in which ranges must be given is xrange and yrange.
In parametric mode, the order for the plot command is trange, xrange, and yrange. The following plot command shows setting the trange to [-pi:pi], the xrange to [-1.3:1.3] and the yrange to [-1:1] for the duration of the graph:
plot [-pi:pi] [-1.3:1.3] [-1:1] sin(t),t**2
Note that the x2range and y2range cannot be specified here---set x2range and set y2range must be used.
Ranges are interpreted in the order listed above for the appropriate mode. Once all those needed are specified, no further ones must be listed, but unneeded ones cannot be skipped---use an empty range [] as a placeholder.
* can be used to allow autoscaling of either of min and max. See also set autoscale.
Ranges specified on the plot or splot command line affect only that graph; use the set xrange, set yrange, etc., commands to change the default ranges for future graphs.
With time data, you must provide the range (in the same manner as the time appears in the datafile) within quotes. gnuplot uses the timefmt string to read the value---see set timefmt.
Examples:
This uses the current ranges:
plot cos(x)
This sets the x range only:
plot [-10:30] sin(pi*x)/(pi*x)
This is the same, but uses t as the dummy-variable:
plot [t = -10 :30] sin(pi*t)/(pi*t)
This sets both the x and y ranges:
plot [-pi:pi] [-3:3] tan(x), 1/x
This sets only the y range, and turns off autoscaling on both axes:
plot [ ] [-2:sin(5)*-8] sin(x)**besj0(x)
This sets xmax and ymin only:
plot [:200] [-pi:] exp(sin(x))
This sets the x range for a timeseries:
set timefmt "%d/%m/%y %H:%M"
plot ["1/6/93 12:00":"5/6/93 12:00"] 'timedata.dat'
A line title for each function and data set appears in the key, accompanied by a sample of the line and/or symbol used to represent it. It can be changed by using the title option.
Syntax:
title "<title>" | notitle
where <title> is the new title of the line and must be enclosed in quotes. The quotes will not be shown in the key. A special character may be given as a backslash followed by its octal value ("\345"). The tab character "\t" is understood. Note that backslash processing occurs only for strings enclosed in double quotes---use single quotes to prevent such processing. The newline character "\n" is not processed in key entries in either type of string.
The line title and sample can be omitted from the key by using the keyword notitle. A null title (title '') is equivalent to notitle. If only the sample is wanted, use one or more blanks (title ' ').
By default the line title is the function or file name as it appears on the plot command. If it is a file name, any datafile modifiers specified will be included in the default title.
The layout of the key itself (position, title justification, etc.) can be controlled by set key. Please see set key for details.
Examples:
This plots y=x with the title 'x':
plot x
This plots x squared with title "x^2" and "data.1" with title 'measured data':
plot x**2 title "x^2", "data.1" t 'measured data'
This puts an untitled circular border around a polar graph:
set polar; plot my_function(t), 1 notitle
Functions and data may be displayed in one of a large number of styles. The with keyword provides the means of selection.
Syntax:
with <style> { {linestyle | ls <line_style>}
| {{linetype | lt <line_type>}
{linewidth | lw <line_width>}
{pointtype | pt <point_type>}
{pointsize | ps <point_size>}} }
where <style> is either lines, points, linespoints, impulses, dots, steps, fsteps, histeps, errorbars, xerrorbars, yerrorbars, xyerrorbars, boxes, boxerrorbars, boxxyerrorbars, financebars, candlesticks or vector. Some of these styles require additional information. See set style <style> for details of each style.
Default styles are chosen with the set function style and set data style commands.
By default, each function and data file will use a different line type and point type, up to the maximum number of available types. All terminal drivers support at least six different point types, and re-use them, in order, if more are required. The LaTeX driver supplies an additional six point types (all variants of a circle), and thus will only repeat after 12 curves are plotted with points. The PostScript drivers (postscript) supplies a total of 64.
If you wish to choose the line or point type for a single plot, <line_type> and <point_type> may be specified. These are positive integer constants (or expressions) that specify the line type and point type to be used for the plot. Use test to display the types available for your terminal.
You may also scale the line width and point size for a plot by using <line_width> and <point_size>, which are specified relative to the default values for each terminal. The pointsize may also be altered globally---see set pointsize for details. But note that both <point_size> as set here and as set by set pointsize multiply the default point size---their effects are not cumulative. That is, set pointsize 2; plot x w p ps 3 will use points three times default size, not six.
If you have defined specific line type/width and point type/size combinations with set linestyle, one of these may be selected by setting <line_style> to the index of the desired style.
The keywords may be abbreviated as indicated.
Note that the linewidth and pointsize options are not supported by all terminals.
Examples:
This plots sin(x) with impulses:
plot sin(x) with impulses
This plots x with points, x**2 with the default:
plot x*y w points, x**2 + y**2
This plots tan(x) with the default function style, "data.1" with lines:
plot [ ] [-2:5] tan(x), "data.1" with l
This plots "leastsq.dat" with impulses:
plot 'leastsq.dat' w i
This plots the data file 'population' with boxes:
plot "population" with boxes
This plots "exper.dat" with errorbars and lines connecting the points ('exper.dat' should have three or four data columns):
plot 'exper.dat' w lines, 'exper.dat' notitle w errorbars
This plots sin(x) and cos(x) with linespoints, using the same line type but different point types:
plot sin(x) with linesp lt 1 pt 3, cos(x) with linesp lt 1 pt 4
This plots file "data" with points of type 3 and twice usual size:
plot "data" with points pointtype 3 pointsize 2
This plots two data sets with lines differing only by weight:
plot "d1" t "good" w l lt 2 lw 3, "d2" t "bad" w l lt 2 lw 1
See set style to change the default styles. Styles demos.
The print command prints the value of <expression> to the screen. It is synonymous with pause 0. <expression> may be anything that gnuplot can evaluate that produces a number, or it can be a string.
Syntax:
print <expression> {, <expression>, ...}
See expressions.
The pwd command prints the name of the working directory to the screen.
The exit and quit commands and END-OF-FILE character will exit gnuplot. Each of these commands will clear the output device (as does the clear command) before exiting.
The replot command without arguments repeats the last plot or splot command. This can be useful for viewing a plot with different set options, or when generating the same plot for several devices.
Arguments specified after a replot command will be added onto the last plot or splot command (with an implied ',' separator) before it is repeated. replot accepts the same arguments as the plot and splot commands except that ranges cannot be specified. Thus you can use replot to plot a function against the second axes if the previous command was plot but not if it was splot, and similarly you can use replot to add a plot from a binary file only if the previous command was splot.
N.B.---use of
plot '-' ; ... ; replot
is not recommended. gnuplot does not store the inline data internally, so since replot appends new information to the previous plot and then executes the modified command, the '-' from the initial plot will expect to read inline data again.
Note that replot does not work in multiplot mode, since it reproduces only the last plot rather than the entire screen.
See also command-line-editing for ways to edit the last plot (splot) command.
The reread command causes the current gnuplot command file, as specified by a load command or on the command line, to be reset to its starting point before further commands are read from it. This essentially implements an endless loop of the commands from the beginning of the command file to the reread command. (But this is not necessarily a disaster---reread can be very useful when used in conjunction with if. See if for details.) The reread command has no effect if input from standard input.
Examples:
Suppose the file "looper" contains the commands
a=a+1
plot sin(x*a)
pause -1
if(a<5) reread
and from within gnuplot you submit the commands
a=0
load 'looper'
The result will be four plots (separated by the pause message).
Suppose the file "data" contains six columns of numbers with a total yrange from 0 to 10; the first is x and the next are five different functions of x. Suppose also that the file "plotter" contains the commands
c_p = c_p+1
plot "$0" using 1:c_p with lines linetype c_p
if(c_p < n_p) reread
and from within gnuplot you submit the commands
n_p=6
c_p=1
set nokey
set yrange [0:10]
set multiplot
call 'plotter' 'data'
set nomultiplot
The result is a single graph consisting of five plots. The yrange must be set explicitly to guarantee that the five separate graphs (drawn on top of each other in multiplot mode) will have exactly the same axes. The linetype must be specified; otherwise all the plots would be drawn with the same type. Reread Animation Demo
The reset command causes all options that can be set with the set command to take on their default values. The only exceptions are that the terminal set with set term and the output file set with set output are left unchanged. This command is useful, e.g., to restore the default settings at the end of a command file, or to return to a defined state after lots of settings have been changed within a command file. Please refer to the set command to see the default values that the various options take.
The save command saves user-defined functions, variables, set options, or all three, plus the last plot (splot) command to the specified file.
Syntax:
save {<option>} "<filename>"
where <option> is functions, variables or set. If no option is used, gnuplot saves functions, variables, set options and the last plot (splot) command.
saved files are written in text format and may be read by the load command.
The filename must be enclosed in quotes.
Examples:
save "work.gnu"
save functions 'func.dat'
save var 'var.dat'
save set "options.dat"
The set command sets _lots_ of options. No screen is drawn, however, until a plot, splot, or replot command is given.
The show command shows their settings. show all shows all the settings.
If a variable contains time/date data, show will display it according to the format currently defined by set timefmt, even if that was not in effect when the variable was initially defined.
angles
arrow
autoscale
bar
bmargin
border
boxwidth
clabel
clip
cntrparam
contour
data style
dgrid3d
dummy
encoding
format
function style
functions
grid
hidden3d
isosamples
key
label
linestyle
lmargin
locale
logscale
mapping
margin
missing
multiplot
mx2tics
mxtics
my2tics
mytics
mztics
offsets
origin
output
parametric
pointsize
polar
rmargin
rrange
samples
size
style
surface
terminal
tics
ticslevel
ticscale
timestamp
timefmt
title
tmargin
trange
urange
variables
view
vrange
x2data
x2dtics
x2label
x2mtics
x2range
x2tics
x2zeroaxis
xdata
xdtics
xlabel
xmtics
xrange
xtics
xzeroaxis
y2data
y2dtics
y2label
y2mtics
y2range
y2tics
y2zeroaxis
ydata
ydtics
ylabel
ymtics
yrange
ytics
yzeroaxis
zdata
zdtics
zero
zeroaxis
zlabel
zmtics
zrange
ztics
By default, gnuplot assumes the independent variable in polar graphs is in units of radians. If set angles degrees is specified before set polar, then the default range is [0:360] and the independent variable has units of degrees. This is particularly useful for plots of data files. The angle setting also applies to 3-d mapping as set via the set mapping command.
Syntax:
set angles {degrees | radians}
show angles
The angle specified in set grid polar is also read and displayed in the units specified by set angles.
set angles also affects the arguments of the machine-defined functions sin(x), cos(x) and tan(x), and the outputs of asin(x), acos(x), atan(x), atan2(x), and arg(x). It has no effect on the arguments of hyperbolic functions or Bessel functions. Note that the output of inverse hyperbolic functions of complex arguments are effected, however; if these functions are used, set angles radians must be in effect:
x={1.0,0.1}
set angles radians
y=sinh(x)
print y #prints {1.16933, 0.154051}
print asinh(y) #prints {1.0, 0.1}
but
set angles degrees
y=sinh(x)
print y #prints {1.16933, 0.154051}
print asinh(y) #prints {57.29578, 5.729578}
Polar plot using `set angles`.
Arbitrary arrows can be placed on a plot using the set arrow command.
Syntax:
set arrow {<tag>} {from <position>} {to <position>} {{no}head}
{ {linestyle | ls <line_style>}
| {linetype | lt <line_type>}
{linewidth | lw <line_width} }
set noarrow {<tag>}
show arrow
<tag> is an integer that identifies the arrow. If no tag is given, the lowest unused tag value is assigned automatically. The tag can be used to delete or change a specific arrow. To change any attribute of an existing arrow, use the set arrow command with the appropriate tag and specify the parts of the arrow to be changed.
The <position>s are specified by either x,y or x,y,z, and may be preceded by first, second, graph, or screen to select the coordinate system. Unspecified coordinates default to 0. The endpoints can be specified in one of four coordinate systems---first or second axes, graph or screen. See coordinates for details. A coordinate system specifier does not carry over from the "from" position to the "to" position. Arrows outside the screen boundaries are permitted but may cause device errors.
Specifying nohead produces an arrow drawn without a head---a line segment. This gives you yet another way to draw a line segment on the plot. By default, arrows have heads.
The line style may be selected from a user-defined list of line styles (see set linestyle) or may be defined here by providing values for <line_type> (an index from the default list of styles) and/or <line_width> (which is a multiplier for the default width).
Note, however, that if a user-defined line style has been selected, its properties (type and width) cannot be altered merely by issuing another set arrow command with the appropriate index and lt or lw.
Examples:
To set an arrow pointing from the origin to (1,2) with user-defined style 5, use:
set arrow to 1,2 ls 5
To set an arrow from bottom left of plotting area to (-5,5,3), and tag the arrow number 3, use:
set arrow 3 from graph 0,0 to -5,5,3
To change the preceding arrow to end at 1,1,1, without an arrow head and double its width, use:
set arrow 3 to 1,1,1 nohead lw 2
To draw a vertical line from the bottom to the top of the graph at x=3, use:
set arrow from 3, graph 0 to 3, graph 1 nohead
To delete arrow number 2, use:
set noarrow 2
To delete all arrows, use:
set noarrow
To show all arrows (in tag order), use:
show arrow
Arrows Demos.
Autoscaling may be set individually on the x, y or z axis or globally on all axes. The default is to autoscale all axes.
Syntax:
set autoscale {<axes>{min|max}}
set noautoscale {<axes>{min|max}}
show autoscale
where <axes> is either x, y, z, x2, y2 or xy. A keyword with min or max appended (this cannot be done with xy) tells gnuplot to autoscale just the minimum or maximum of that axis. If no keyword is given, all axes are autoscaled.
When autoscaling, the axis range is automatically computed and the dependent axis (y for a plot and z for splot) is scaled to include the range of the function or data being plotted.
If autoscaling of the dependent axis (y or z) is not set, the current y or z range is used.
Autoscaling the independent variables (x for plot and x,y for splot) is a request to set the domain to match any data file being plotted. If there are no data files, autoscaling an independent variable has no effect. In other words, in the absence of a data file, functions alone do not affect the x range (or the y range if plotting z = f(x,y)).
Please see set xrange for additional information about ranges.
The behavior of autoscaling remains consistent in parametric mode, (see set parametric). However, there are more dependent variables and hence more control over x, y, and z axis scales. In parametric mode, the independent or dummy variable is t for plots and u,v for splots. autoscale in parametric mode, then, controls all ranges (t, u, v, x, y, and z) and allows x, y, and z to be fully autoscaled.
Autoscaling works the same way for polar mode as it does for parametric mode for plot, with the extension that in polar mode set dummy can be used to change the independent variable from t (see set dummy).
When tics are displayed on second axes but no plot has been specified for those axes, x2range and y2range are inherited from xrange and yrange. This is done _before_ xrange and yrange are autoextended to a whole number of tics, which can cause unexpected results.
Examples:
This sets autoscaling of the y axis (other axes are not affected):
set autoscale y
This sets autoscaling only for the minimum of the y axis (the maximum of the y axis and the other axes are not affected):
set autoscale ymin
This sets autoscaling of the x and y axes:
set autoscale xy
This sets autoscaling of the x, y, z, x2 and y2 axes:
set autoscale
This disables autoscaling of the x, y, z, x2 and y2 axes:
set noautoscale
This disables autoscaling of the z axis only:
set noautoscale z
When in parametric mode (set parametric), the xrange is as fully scalable as the y range. In other words, in parametric mode the x axis can be automatically scaled to fit the range of the parametric function that is being plotted. Of course, the y axis can also be automatically scaled just as in the non-parametric case. If autoscaling on the x axis is not set, the current x range is used.
Data files are plotted the same in parametric and non-parametric mode. However, there is a difference in mixed function and data plots: in non-parametric mode with autoscaled x, the x range of the datafile controls the x range of the functions; in parametric mode it has no influence.
For completeness a last command set autoscale t is accepted. However, the effect of this "scaling" is very minor. When gnuplot determines that the t range would be empty, it makes a small adjustment if autoscaling is true. Otherwise, gnuplot gives an error. Such behavior may, in fact, not be very useful and the command set autoscale t is certainly questionable.
splot extends the above ideas as you would expect. If autoscaling is set, then x, y, and z ranges are computed and each axis scaled to fit the resulting data.
When in polar mode (set polar), the xrange and the yrange are both found from the polar coordinates, and thus they can both be automatically scaled. In other words, in polar mode both the x and y axes can be automatically scaled to fit the ranges of the polar function that is being plotted.
When plotting functions in polar mode, the rrange may be autoscaled. When plotting data files in polar mode, the trange may also be autoscaled. Note that if the trange is contained within one quadrant, autoscaling will produce a polar plot of only that single quadrant.
Explicitly setting one or two ranges but not others may lead to unexpected results. See polar demos
The set bar command controls the tics at the ends of errorbars.
Syntax:
set bar {small | large | <size>}
show bar
small is a synonym for 0.0, and large for 1.0. The default is 1.0 if no size is given.
The command set bmargin sets the size of the bottom margin. Please see set margin for details.
The set border and set noborder commands control the display of the graph borders for the plot and splot commands.
Syntax:
set border {<integer>}
set noborder
show border
The borders are encoded in a 12-bit integer. The bottom four bits control the border for plot and the sides of the base for splot, the next four bits control the verticals in splot and the top four bits control the edges on top of the splot. In detail, the <integer> should be the sum of the appropriate entries from the following table:
plot border
and
splot base splot verticals splot top
bottom (south) 1 16 256
left (west) 2 32 512
top (north) 4 64 1024
right (east) 8 128 2048
The default is 31, which is all four sides for plot, and base and z axis for splot.
To have tics on edges other than bottom and left, disable the usual tics and enable the second axes.
Examples:
Draw all borders:
set border
Draw only the SOUTHWEST borders:
set border 3
Draw a complete box around a splot:
set border 4095
Draw a partial box, omitting the front vertical:
set border 127+256+512
Draw only the NORTHEAST borders:
set noxtics; set noytics; set x2tics; set y2tics; set border 12
The set boxwidth command is used to set the default width of boxes in the boxes and boxerrorbars styles.
Syntax:
set boxwidth {<width>}
show boxwidth
If a data file is plotted without the width being specified in the third, fourth, or fifth column (or using entry), or if a function is plotted, the width of each box is set by the set boxwidth command. (If a width is given both in the file and by the set boxwidth command, the one in the file is used.) If the width is not specified in one of these ways, the width of each box will be calculated automatically so that it touches the adjacent boxes. In a four-column data set, the fourth column will be interpreted as the box width unless the width is set to -2.0, in which case the width will be calculated automatically. See set style boxerrorbars for more details.
To set the box width to automatic use the command
set boxwidth
or, for four-column data,
set boxwidth -2
The same effect can be achieved with the using keyword in plot:
plot 'file' using 1:2:3:4:(-2)
<