Re: Plotting multiple functions with different plot ranges?
- To: mathgroup at smc.vnet.net
- Subject: [mg33568] Re: [mg33546] Plotting multiple functions with different plot ranges?
- From: BobHanlon at aol.com
- Date: Sun, 31 Mar 2002 04:09:28 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
In a message dated 3/29/02 8:44:16 AM, siegman at stanford.edu writes: >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? > Needs["Graphics`Graphics`"]; Needs["Graphics`Colors`"]; DisplayTogether[ Plot[Cos[x], {x,0,2Pi},PlotStyle->Blue], Plot[Sin[x], {x,Pi/2,3Pi/2},PlotStyle->Red], Ticks->{PiScale,Automatic}]; Bob Hanlon Chantilly, VA USA