# Can I limit PlotRange for 1 function in a Plot?

I have a 2D Plot of 3 functions

Plot[ { f1[x], f2[x], f3[x] }, { x, 8, 18 } ]


where I want f3[x] only plotted for the range [10, 18] instead of [8, 18]. Is that possible?

-
– image_doctor Jun 20 '12 at 10:47

You can use ConditionalExpression (new in version 8) e.g.

Plot[{f1[x], f2[x], ConditionalExpression[f3[x], x > 10]}, {x, 8, 18}]


For example, let's define :

f1[x_] := -4/5 Sin[x]
f2[x_] := Sin[2 x]^2 - 1/2
f3[x_] := Sin[3 x]^5


now

Plot[{ f1[x], f2[x], ConditionalExpression[f3[x], x > 10]}, {x, 8, 18},
PlotStyle -> {Thick, Thick, Thickness[0.007]}]


The thickest curve is the graph of of f3 in the expected region though f3 is defined for all real (even complex) numbers.

-
Perfect. Thanks a bunch. – stevenvh Jun 20 '12 at 9:55
Alternatively, there's Plot[{f1[x], f2[x], Piecewise[{{f3[x], x > 10}}, Indeterminate]}, {x, 8, 18}]. – J. M. Jun 20 '12 at 10:49
@stevenvh I'm glad I could help. – Artes Jun 20 '12 at 12:01
@J.M. that version also works on v7 whereas ConditionalExpression does not. Please post that as an answer, or I shall. – Mr.Wizard Jun 20 '12 at 17:43

A solution using individual plots combined using Show.

f1[x_] := 1/4 Sin[x]
f2[x_] := 1/2 Sin[2 x]^2
f3[x_] := Sin[3 x]^3


Define a function to plot some functions over some ranges:

Attributes@plotFuncs = {HoldFirst};
plotFuncs[{funcs_, ranges_, opts_}] :=
Show[Block[Evaluate@Union@ranges[[All, 1]],
Plot[#1[First@#2], #2, #3] &, {funcs, ranges,
opts}]], PlotRange -> All]


Plot the three functions:

plotFuncs[{{f1, f2, f3}, {{x, 8, 18}, {y, 8, 18}, {x, 10, 18}},
{PlotStyle -> Red, PlotStyle -> Blue, PlotStyle -> Darker@Green}}]


-
Thanks for your answer. I'm a beginner at Mathematica, and accepted Artes' answer because it's easier to understand. But thanks again. – stevenvh Jun 20 '12 at 16:21
#@stevenvh No problem, glad you got the answer you needed :) – image_doctor Jun 20 '12 at 16:49

At Mr. Wizard's urging: Plot[{f1[x], f2[x], Piecewise[{{f3[x], x > 10}}, Indeterminate]}, {x, 8, 18}] works nicely as an alternative to Artes's answer.

-