MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

Plotting multiple functions with different plot ranges?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg33546] Plotting multiple functions with different plot ranges?
  • From: aes <siegman at stanford.edu>
  • Date: Fri, 29 Mar 2002 06:13:57 -0500 (EST)
  • Organization: Stanford University
  • Sender: owner-wri-mathgroup at wolfram.com

Is there any approved way to plot multiple functions with different plot ranges 
in a single Plot command

Suppose, e.g., I want to plot Cos[x] over the full range from 0 to 2 Pi but 
Sin[x] only over the subrange from Pi.2 to 3Pi/2, with just one Plot command.

My naive initial attempt, namely

   Plot[{Cos[x], If[x > Pi/2 && x < 3Pi/2, Sin[x]]},  {x, 0, 2Pi}, 
    PlotRange -> {{0, 2Pi}, {-1,1}},  PlotStyle -> Thickness[0.008]];

does what's wanted but generates a lot of "Plot::plnr" error messages.

Workarounds include:

1)  Turn Off the error messages (dangerous?)

2)  Add a second argument to the If[ ]  statement that sets the second function 
to some constant  c1  outside the desired subrange, i.e.

   Plot[{Cos[x], If[x > Pi/2 && x < 3Pi/2, Sin[x], c1]}, {x, 0, 2Pi}, 
    PlotRange -> {{0, 2Pi}, {-1,1}}, PlotStyle -> Thickness[0.008]];

where  c1  could be 0 or a number that falls on an axis line or outside the 
PlotRange for the plot. 

(Doing this still gives unwanted vertical "jump lines" at the ends of the 
subrange, along with unwanted effects if line Thickness is increased).

3)  Make two Plots and combine using Show (tedious).

4)  Set second function value to Null outside the subrange? (doesn't seem to 
work).

Other solutions?


  • Prev by Date: Re: Running Math Kernel Alone in OS X
  • Next by Date: Re: Q: Using dynamic referencing for numbered equations
  • Previous by thread: Automatic restart
  • Next by thread: Re: Plotting multiple functions with different plot ranges?