Functions

Arguments to math functions in gnuplot can be integer, real, or complex unless otherwise noted. Functions that accept or return angles (e.g. sin(x)) treat angle values as radians, but this may be changed to degrees using the command set angles.

Math library functions
Function Arguments Returns
     
abs(x) any absolute value of $x$, $\vert x\vert$; same type
abs(x) complex length of $x$, $\sqrt{{\mbox{real}(x)^{2} +
\mbox{imag}(x)^{2}}}$
acos(x) any $\cos^{-1} x$ (inverse cosine)
acosh(x) any $\cosh^{-1} x$ (inverse hyperbolic cosine)
airy(x) any Airy function Ai(x)
arg(x) complex the phase of $x$
asin(x) any $\sin^{-1} x$ (inverse sin)
asinh(x) any $\sinh^{-1} x$ (inverse hyperbolic sin)
atan(x) any $\tan^{-1} x$ (inverse tangent)
atan2(y,x) int or real $\tan^{-1} (y/x)$ (inverse tangent)
atanh(x) any $\tanh^{-1} x$ (inverse hyperbolic tangent)
EllipticK(k) real k $\in$ (-1:1) $K(k)$ complete elliptic integral of the first kind
EllipticE(k) real k $\in$ [-1:1] $E(k)$ complete elliptic integral of the second kind
EllipticPi(n,k) real n$<$1, real k $\in$ (-1:1) $\Pi(n,k)$ complete elliptic integral of the third kind
besj0(x) int or real $J_{0}$ Bessel function of $x$ in radians
besj1(x) int or real $J_{1}$ Bessel function of $x$ in radians
besjn(n,x) int, real $J_{n}$ Bessel function of $x$ in radians
besy0(x) int or real $Y_{0}$ Bessel function of $x$ in radians
besy1(x) int or real $Y_{1}$ Bessel function of $x$ in radians
besyn(n,x) int, real $Y_{n}$ Bessel function of $x$ in radians
besi0(x) real Modified Bessel function of order 0, $x$ in radians
besi1(x) real Modified Bessel function of order 1, $x$ in radians
besin(n,x) int, real Modified Bessel function of order n, $x$ in radians
ceil(x) any $\lceil x \rceil$, smallest integer not less than $x$ (real part)
cos(x) any $\cos x$, cosine of $x$
cosh(x) any $\cosh x$, hyperbolic cosine of $x$ in radians
erf(x) any $\mbox{erf}(\mbox{real}(x))$, error function of real($x$)
erfc(x) any $\mbox{erfc}(\mbox{real}(x))$, 1.0 - error function of real($x$)
exp(x) any $e^{x}$, exponential function of $x$
expint(n,x) int $n\ge0$, real $x\ge0$ $E_n(x)=\int_1^\infty t^{-n} e^{-xt}\,dt$, exponential integral of $x$
floor(x) any $\lfloor x \rfloor$, largest integer not greater than $x$ (real part)
gamma(x) any $\mbox{gamma}(\mbox{real}(x))$, gamma function of real($x$)
ibeta(p,q,x) any $\mbox{ibeta}(\mbox{real}(p,q,x))$, ibeta function of real($p$,$q$,$x$)
inverf(x) any inverse error function of real($x$)
igamma(a,x) any $\mbox{igamma}(\mbox{real}(a,x))$, igamma function of real($a$,$x$)
imag(x) complex imaginary part of $x$ as a real number
invnorm(x) any inverse normal distribution function of real($x$)
int(x) real integer part of $x$, truncated toward zero
lambertw(x) real Lambert W function
lgamma(x) any $\mbox{lgamma}(\mbox{real}(x))$, lgamma function of real($x$)
log(x) any $\log_{e} x$, natural logarithm (base $e$) of $x$
log10(x) any $\log_{10} x$, logarithm (base $10$) of $x$
norm(x) any normal distribution (Gaussian) function of real($x$)
rand(x) int pseudo random number in the open interval (0:1)
real(x) any real part of $x$
sgn(x) any 1 if $x>0$, -1 if $x<0$, 0 if $x=0$. imag($x$) ignored
sin(x) any $\sin x$, sine of $x$
sinh(x) any $\sinh x$, hyperbolic sine of $x$ in radians
sqrt(x) any $\sqrt{x}$, square root of $x$
tan(x) any $\tan x$, tangent of $x$
tanh(x) any $\tanh x$, hyperbolic tangent of $x$ in radians
voigt(x,y) real Voigt/Faddeeva function $\frac{y}{\pi} \int{\frac{exp(-t^2)}{(x-t)^2+y^2}}dt$
    Note: voigt$(x,y)$ = $real($faddeeva$(x+iy))$
     

Special functions from libcerf (only if available)
Function Arguments Returns
     
cerf(z) complex complex error function
cdawson(z) complex complex extension of Dawson's integral $D(z)={\frac{\sqrt{\pi}}{2}e^{-z^2} erfi(z)} $
faddeeva(z) complex rescaled complex error function $w(z) = e^{-z^2}~ erfc(-iz) $
erfi(x) real imaginary error function $erf(x) = -i * erf(ix)$
VP(x,$\sigma$,$\gamma$) real Voigt profile $VP(x,\sigma,\gamma) = {\int^{\infty}_{-\infty}{G(x^\prime;\sigma) L(x-x^\prime;\gamma) dx^\prime }} $
     

String functions
Function Arguments Returns
gprintf("format",x,...) any string result from applying gnuplot's format parser
sprintf("format",x,...) multiple string result from C-language sprintf
strlen("string") string number of characters in string
strstrt("string","key") strings int index of first character of substring "key"
substr("string",beg,end) multiple string "string"[beg:end]
strftime("timeformat",t) any string result from applying gnuplot's time parser
strptime("timeformat",s) string seconds since year 1970 as given in string s
system("command") string string containing output stream of shell command
trim(" string ") string string without leading or trailing whitespace
word("string",n) string, int returns the nth word in "string"
words("string") string returns the number of words in "string"

other gnuplot functions
Function Arguments Returns
column(x) int or string column $x$ during datafile input
columnhead(x) int string containing first entry of column $x$ in datafile.
exists("X") string returns 1 if a variable named X is defined, 0 otherwise.
hsv2rgb(h,s,v) h,s,v $\in$ [0:1] 24bit RGB color value.
palette(z) double RGB palette color mapped to z.
stringcolumn(x) int or string content of column $x$ as a string.
timecolumn(N,"timeformat") int, string time data from column $N$ during data input.
tm_hour(t) time in sec the hour (0..23)
tm_mday(t) time in sec the day of the month (1..31)
tm_min(t) time in sec the minute (0..59)
tm_mon(t) time in sec the month (0..11)
tm_sec(t) time in sec the second (0..59)
tm_wday(t) time in sec the day of the week (Sun..Sat) as (0..6)
tm_week(t) time in sec week of year in ISO8601 "week date" system (1..53)
tm_yday(t) time in sec the day of the year (0..365)
tm_year(t) time in sec the year
time(x) any the current system time in seconds
valid(x) int test validity of $\mbox{column}(x)$ during datafile input
value("name") string returns the value of the named variable.
voxel(x,y,z) real value of the active grid voxel containing point (x,y,z)


Subsections