Skip to content
ihateDesmos

How to graph piecewise functions on Desmos

Updated 6 November 2026 · An independent guide, not from 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}.

What to type
y = {x < 0: -x, x >= 0: x^2}y = {x < -1: -2, -1 <= x <= 1: x, 2}
−4−224240
Open in calculator
A piecewise function: −x to the left of 0, and x² to the right.

Step by step

  1. 1
    Type y = {, and Desmos adds the closing brace for you.
  2. 2
    Type a condition, a colon, then the function for that piece: x < 0: -x.
  3. 3
    Type a comma and add the next piece: x >= 0: x^2.
  4. 4
    To 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?
Use braces and colons: y = {x < 0: -x, x >= 0: x^2}. Each piece is a condition, a colon and the function, separated by commas.
Why does my piecewise function not show up?
Check for a missing colon or comma, and check that the window shows the x-values your conditions cover. A condition on y instead of x also won’t work in this form.
How do I add an “otherwise” case?
Leave off the condition on the last piece: y = {x < 0: -x, 2} gives 2 for all other x.
How do I show an open circle at the end of a piece?
Plot the point on its own line, then click and hold its coloured icon to choose the open-circle style.

Keep going

Or try it in ihateDesmos

The same equations work here, with algebra, steps and exports built in. It is free, with no account.

Open the calculator