How to Graph Piecewise Functions in Desmos
Graph pieces, restrictions and endpoints
By JasonPublished 2 min read
On this page

To graph a piecewise function in Desmos, use curly braces with a condition, a colon and the rule for each piece, separated by commas: y={x<0: -x, x>=0: x^2}. To graph only part of one function, put a condition in braces after it: y=2x+1{0<x<5}. Try the examples in our free Desmos calculator.
A piecewise function uses different rules for different inputs. A domain restriction keeps only the part of a graph whose x-values satisfy a condition. Both use braces, but their syntax has a useful difference: a restriction goes after a rule; a piecewise definition puts each condition and its rule inside the braces.
Restrict the domain of a graph
Start with
- Type
y=2x+1. - Immediately after the rule, type
{. - Type
0<x<5inside the braces. - Finish with
}. The completed line isy=2x+1{0<x<5}.
The graph is the part of the line between
To include both boundaries, use y=2x+1{0<=x<=5}. Type <= for the less-than-or-equal-to sign and >= for greater-than-or-equal-to. You can include just one boundary: 0<=x<5 includes 0 and excludes 5. The direction of each inequality matters, so read the condition from left to right before graphing.
A domain restriction tests x-values. You can also restrict y, which keeps only the part of a graph in a chosen range of outputs. Type y=2x+1{1<y<7} to keep the part where
Check the condition
Pick a point you expect to keep. For
Write a piecewise function
Now give Desmos a different rule on each side of
- Type
y=and then{. - Type the first condition,
x<0. - Type a colon,
:, then the first rule,-x. - Type a comma,
,, to separate the pieces. - Type the second condition,
x>=0, a colon, and the second rule,x^2. - Finish with
}. The line isy={x<0: -x, x>=0: x^2}.
Read each piece as “if this condition is true, use this rule.” At
For three pieces, follow the same pattern and add another comma. Use
- Type
y={and thenx<-1:x+2. - Type
,and then-1<=x<2:1. - Type another
,and thenx>=2:x-1. - Finish with
}. The whole line isy={x<-1:x+2, -1<=x<2:1, x>=2:x-1}.
The middle piece is a horizontal segment at
Common mistake
Do not reverse the condition and the rule. Inside a piecewise definition, write x<0:-x, not -x:x<0. The colon separates the condition from the rule; the comma separates one piece from the next.
Add open and closed endpoints
A strict inequality such as
For example, graph y={x<0:x+1,x>=0:x}. The left piece approaches
- On a new line, type
(0,0)to add the closed point. - On another line, type
(0,1)for the excluded endpoint. - Press and hold the colored icon beside the
(0,1)expression. In the point style options, select the open circle.
The button starts with both points filled. Change the style of
Name the function and evaluate it
Replace y= with f(x)= to give the first two-piece example a name.
- Type
f(x)={x<0:-x,x>=0:x^2}. - On the next line, type
f(-2). Desmos shows 2. - On another line, type
f(3). Desmos shows 9.
The number in parentheses is the input. Decide which condition it satisfies, then substitute into that piece. The calculator does that selection for you. See SAT functions for more practice with inputs, outputs and graphs.
Absolute value is a piecewise function
The graph of y=|x| on one line and y={x<0:-x,x>=0:x} on the next. The two graphs lie on top of each other.
For instance,
Where this helps on the SAT
The SAT rarely writes piecewise functions. Domain restrictions are useful when a model only makes sense over certain values, such as time from 0 onward. The restriction makes the relevant part of a graph easier to see; it does not change the rule within that interval.
Practice question · Functions
Show the Detailed Explanation
Put 9 into the rule:
In Desmos, type W(t)=95-4t, then W(9) on the next line. Desmos shows 59. To see the model from the start until the tank is empty, graph y=95-4x{0<=x<=23.75}:
For more calculator techniques, see key Desmos features, then practice in Functions topic training or Desmos Skills training.
Piecewise graphs in Desmos
- Put a restriction after a rule:
y=2x+1{0<x<5}. Use in the condition to restrict outputs instead. - Inside a piecewise definition, type each condition, a colon and its rule; separate pieces with commas.
- Check each boundary for inclusion, and add open or filled endpoint points yourself.
- Name the rule
f(x)and type a value such asf(-2)to evaluate it.


