Skip to content

Grapher syntax reference

The complete reference for grapher expressions and note graph blocks, with examples of every kind of plot.

The grapher reads the same plain notation you would type into a calculator. This page is the full reference: the kinds of plot, how expressions are parsed, and every function and constant. The same syntax is used inside notes in graph blocks.

Kinds of plot#

The grapher decides what to draw from the shape of what you type.

You typePlotted asExample
An expression in xy=f(x)y = f(x)x^2 - 3x
y = an expression in xy=f(x)y = f(x)y = e^-x sin x
x = an expression in yx=g(y)x = g(y)x = y^2 - 2
An expression in y onlyx=g(y)x = g(y)y^2 - 2
An equation in x and yImplicit curvex^2 + y^2 = 9
An inequality in x and yShaded regiony < 2x + 1
r = an expression in θPolar curver = 1 + cos θ
(x(t), y(t))Parametric curve(cos t, sin 2t)
(a, b) with numbersPoint(2, 3)
A letter = a numberSlidera = 2

Each row holds one expression with at most one =, <, >, <= or >=. A double inequality such as 1 < x < 3 needs two rows.

Functions of x#

Write the right-hand side on its own or with y = in front. Both of these plot the same curve.

x^3 - 3x + 1
y = x^3 - 3x + 1

When you paste LaTeX, a leading f(x) = (or g(x) =, h(x) =) is turned into y =. Typed directly, write y = instead. Functions of yy are plotted sideways with x = …, or by typing an expression in y alone:

y = x^3 - 3x + 1 x = y^2 - 2

Implicit equations#

Any equation involving both x and y is drawn as an implicit curve, so circles, ellipses and curves that are not functions all work.

x^2 + y^2 = 4 x^2/9 + y^2/4 = 1 x y = 1

An expression with both x and y but no = is ambiguous, so the grapher asks you to write it as an equation, such as x^2 + y^2 = 4.

Inequalities#

Use <, >, <= or >= (or ≤ and ≥). The region where the inequality holds is shaded. Strict inequalities draw a dashed boundary; <= and >= draw it solid.

y < 2x + 1 y >= x^2 - 2

Inequalities in one variable, such as x > 1, shade a half-plane.

Polar curves#

Use θ for the angle, or type theta instead. The curve is drawn for 0≤θ≤2π0 \le \theta \le 2\pi.

r = 1 + cos θ r = sin 3θ

An expression in θ alone, without r =, is also drawn as a polar curve.

Parametric curves#

Write a pair (x(t), y(t)) that uses t. The curve is drawn for 0≤t≤2π0 \le t \le 2\pi.

(cos t, sin 2t) (0.5 cos t, 0.5 sin t)

To cover a different range, scale t inside the expressions: (2t, 4t^2) covers 0≤x≤4π0 \le x \le 4\pi.

Points#

A pair of numbers is a point, drawn as a dot labelled with its coordinates. Coordinates can be expressions such as (pi/2, 1), and they can use sliders, so (a, a^2) moves along a parabola as you drag a. Points cannot depend on x or y.

y = x^2 (1, 1) (2, 4)

Sliders#

A row of the form letter = number defines a slider. The value can be any constant expression, such as k = pi/4; once you drag the slider, the row shows the number. Any other letter used in an expression gets a slider automatically, starting at 1.

a = 2
y = a sin(x - b)

Slider names are single letters other than the reserved letters below, upper or lower case, or a letter followed by digits such as a1 or k2. Because a letter followed by digits is always read as one name, write 2x rather than x2.

Reserved letters#

LetterMeaning
x, yCartesian coordinates
tParameter for parametric curves
θ (or theta)Angle for polar curves
rRadius for polar curves
eEuler's number, e≈2.71828e \approx 2.71828

Everything else is free to use as a slider. Function names and the constants pi and tau are read as themselves, not as sliders.

How expressions are read#

The parser follows the conventions you use on paper.

RuleExampleRead as
Multiplication can be implied2x, 3(x + 1), x(x - 2)2x2x, 3(x+1)3(x+1), x(x−2)x(x-2)
Adjacent letters multiplyab xa×b×xa \times b \times x
Powers with ^ or **x^2, x**2x2x^2
Powers group to the right2^3^22(32)=5122^{(3^2)} = 512
A minus sign is allowed after ^e^-xe−xe^{-x}
Functions can skip bracketssin x, sin 2x, ln x^2sin⁡x\sin x, sin⁡2x\sin 2x, ln⁡(x2)\ln(x^2)
Powers of functionssin^2 x(sin⁡x)2(\sin x)^2
Inverse functionssin^-1 x, cos^-1 x, tan^-1 xarcsin⁡x\arcsin x, arccos⁡x\arccos x, arctan⁡x\arctan x
Absolute valueabs(x - 1) or |x - 1|∣x−1∣\lvert x - 1 \rvert
Multiplication signs*, ·, ××\times
Division/1/2x is 12x\tfrac{1}{2}x
Watch out

A function written without brackets takes everything up to the next +, −, * or /. So sin x cos x is read as sin⁡(xcos⁡x)\sin(x \cos x). Write sin(x) cos(x) or sin x * cos x when you mean the product.

Watch out

A power takes only what comes straight after the ^: one number, letter, function or bracket, with an optional minus sign. So e^2x is e2xe^2 x and e^-2x is e−2xe^{-2} x. Write e^(2x) when the whole product is the power.

Function names and constants are recognised even when run together with other letters, so sinx is sin⁡x\sin x and 2pix is 2πx2\pi x. This stops working once a digit is in the run: sin2x is read as a single slider name, so write sin 2x. When in doubt, add a space or brackets.

Numbers can be written as 3, 0.25, .5 or in standard form, 1.5e3. Unicode −, ≤, ≥, ·, ×, π, τ and θ are all accepted.

Constants#

NameValue
pi, ππ≈3.14159\pi \approx 3.14159
tau, τ2π2\pi
ee≈2.71828e \approx 2.71828

Functions#

All trigonometric functions use radians.

FunctionMeaning
sin, cos, tanSine, cosine, tangent
sec, cosec (or csc), cotReciprocal trigonometric functions
arcsin, arccos, arctan (or asin, acos, atan)Inverse trigonometric functions
sinh, cosh, tanhHyperbolic functions
lnNatural logarithm, log⁡e\log_e
log, lg, log10Logarithm base 10
log2Logarithm base 2
expexe^x
sqrt, cbrtSquare root, cube root
absAbsolute value, ∣x∣\lvert x \rvert
floor, ceil, roundRound down, up, or to the nearest integer
sign−1-1, 00 or 11 according to the sign
min(a, b), max(a, b)Smaller or larger of two values
mod(a, b)Remainder of a÷ba \div b, always non-negative
fact(n)n!n!, extended to non-integers by the gamma function
gamma(z)The gamma function, Γ(z)\Gamma(z)
nCr(n, r)Combinations, (nr)\binom{n}{r}
nPr(n, r)Permutations, nPr{}^{n}P_{r}

For logarithms in another base, use the change of base: log⁡3x\log_3 x is ln x / ln 3.

Examples#

GoalType
A quadratic and its rootsy = x^2 - x - 6 (hover the crossings)
A modulus graphy = abs(2x - 3)
Exponential decayy = 100 e^(-0.2 x)
A transformed trig graphy = 3 sin(2(x - pi/4)) + 1 with the π toggle on
A circle with centre (2,−1)(2, -1), radius 3(x - 2)^2 + (y + 1)^2 = 9
The region above a line and below a curvey > x and y < 4 - x^2 on two rows
A tangent with a moving pointy = x^2, y = 2a(x - a) + a^2, (a, a^2)
The binomial coefficients as points(2, nCr(6, 2))
Simple harmonic motiony = A cos(w x) with sliders A and w

Graph blocks in notes#

Notes draw figures with a ```graph fenced block: one instruction per line. Any grapher expression can be a line, plus a few instructions for framing the figure. Blank lines are ignored and lines starting with # are comments.

InstructionEffect
view xmin xmax ymin ymaxSet the visible window. Defaults to view -6 6 -4 4.
radLabel the x-axis in multiples of π
y = … or any expressionPlot it, exactly as in the grapher
(x0, y0) -- (x1, y1)Draw a line segment
(x0, y0) -> (x1, y1)Draw an arrow, with the head at the second point (→ also works)
fill a b y = f(x)Shade between the curve y=f(x)y = f(x) and the x-axis for a≤x≤ba \le x \le b
a = 2Fix a constant used by other lines (no slider is shown in a note)

Numbers in view, fill and coordinates can be expressions such as pi, pi/2 or 2pi. In view and fill each number must be written without spaces, so use pi/2 rather than pi / 2. Segments and arrows need a space either side of -- or ->. A fill only works with a curve of the form y=f(x)y = f(x).

Every line that draws something, or sets a constant, is listed under the figure as its caption, so readers can see exactly what is drawn. Figures in notes do not show points of interest; choose Open in grapher to explore them.

```graph
view 0 2pi -1.5 1.5
rad
y = sin x
y = cos x
fill 0 pi/2 y = sin x
(pi/4, 0) -- (pi/4, 0.7071)
```

That block draws this:

y = sin x y = cos x fill 0 pi/2 y = sin x (pi/4, 0) -- (pi/4, 0.7071)

The window is padded slightly and widened to fit the figure's shape, so curves never touch the frame. Lines that cannot be plotted are reported by pnpm notes:check and shown under the figure, so a broken graph is never silently empty. See Note format for when to use a graph and when to draw a diagram.

Search documentation

Search every page of the Margin docs