How to graph piecewise functions on Desmos
To write a piecewise function in Desmos, use curly braces, with a colon after each condition and a comma between pieces: y = {x < 0: -x, x >= 0: x^2}.
y = {x < 0: -x, x >= 0: x^2}y = {x < -1: -2, -1 <= x <= 1: x, 2}Step by step
- 1Type
y = {, and Desmos adds the closing brace for you. - 2Type a condition, a colon, then the function for that piece:
x < 0: -x. - 3Type a comma and add the next piece:
x >= 0: x^2. - 4To set a value for “everything else”, leave off the last condition:
y = {x < 0: -x, x^2}.
Another way: separate lines
You can also write each piece on its own line, with a restriction: y = -x {x < 0} and y = x^2 {x >= 0}. This draws the same picture, and lets you give each piece a different colour.
Open and closed dots
Desmos doesn’t add open or closed dots at the ends of pieces automatically. Add them yourself by plotting a point on a new line, like (0, 1). Click and hold the coloured icon next to it, then choose the open-circle style for a point that isn’t included.
Typing ≤ and ≥
Type <= or >=, and Desmos converts them to ≤ and ≥. You can chain conditions, like -1 <= x <= 1.
Understanding piecewise functions
The piecewise function grapher explains how to read and write these, with worked examples. |x| and the floor function are the classic examples.
Frequently asked questions
How do you write a piecewise function in Desmos?
Why does my piecewise function not show up?
How do I add an “otherwise” case?
How do I show an open circle at the end of a piece?
Keep going
What piecewise functions mean, with examples.
The same curly braces on one function.
What each piece covers.
Click + and choose table, then type values to plot them.
Turn on Lines in a table, or use one parametric equation.
Type y₁ ~ m x₁ + b below a table, with the tilde.
The same equations work here, with algebra, steps and exports built in. It is free, with no account.