10

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?

stevenvh
  • 6,866
  • 5
  • 41
  • 64
  • 1
    Related:http://mathematica.stackexchange.com/questions/5858/how-do-i-plot-a-function-over-a-subset-of-the-displayed-interval/5862#5862 – image_doctor Jun 20 '12 at 10:47

3 Answers3

16

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]}]

enter image description here

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

stevenvh
  • 6,866
  • 5
  • 41
  • 64
Artes
  • 57,212
  • 12
  • 157
  • 245
9

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]], 
   MapThread[
    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}}]

Mathematica graphics

image_doctor
  • 10,234
  • 23
  • 40
7

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.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574