MathGroup Archive 2004

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

Search the Archive

RE: Problems with Plot in Mathematica 4.0, Combining Plots with Different Domains

  • To: mathgroup at
  • Subject: [mg45846] RE: [mg45806] Problems with Plot in Mathematica 4.0, Combining Plots with Different Domains
  • From: "David Park" <djmp at>
  • Date: Tue, 27 Jan 2004 04:50:39 -0500 (EST)
  • Sender: owner-wri-mathgroup at


There are a number of ways to combine two plots with different domains.
Let's define your two functions.

f1[x_] := 1/2x^2 - x
f2[x_] := -1/2x^2 + x

We could combine them into one function using UnitSteps and make a regular

f[x_] := f1[x](UnitStep[x + 3] - UnitStep[x]) +
    f2[x](UnitStep[x] - UnitStep[x - 3])

Plot[f[x], {x, -4, 4},
    Frame -> True,
    PlotRange -> All];

But if you want to deal with them as separate functions you could combine
two plots with the following statement.

Block[{$DisplayFunction = Identity},
  g1 = Plot[f1[x], {x, -3, 0}];
  g2 = Plot[f2[x], {x, 0, 3}];
Show[g1, g2,
    Frame -> True,
    PlotRange -> {{-4.1, 4.1}, All}];

Here the Block statement gives a local value to $DisplayFunction so as to
supress the side plots. Or you could use the DisplayTogether command from


    Plot[f1[x], {x, -3, 0}], Plot[f2[x], {x, 0, 3}], Frame -> True,
    PlotRange -> {{-4.1, 4.1}, All}];

The last two methods are sometimes a little tricky because they don't always
pick up all Options from the second plot.

Another method is to try the DrawGraphics package from my web site below.


    {Draw[f1[x], {x, -3, 0}],
      Draw[f2[x], {x, 0, 3}]},
    Frame -> True,
    PlotRange -> {{-4.1, 4.1}, All}];

Here the Draw statements are like the Plot statement except they just
extract the primitive graphics without making side plots. You could easily
add in other plot type graphics and Lines, Points, Text primitives or
graphics directives, or you could manipulate the primitive graphics before

David Park
djmp at

From: Manfred Fischer [mailto:manfis at]
To: mathgroup at


I want to plot the two functions in one Plot output
+0.5x^2-x (definition-range -3<=x<=0)
-0.5x^2+x (definition-range 0<=x<=3)

I can't find a mathematica 4.0 solution, please help!

-ManFis -

  • Prev by Date: Re: Equation counting in arXiv style sheet
  • Next by Date: Re: Simple question or how Mathematica getting on my nerves.
  • Previous by thread: Re: RE: GridPlot
  • Next by thread: Integraton & Minimization and complex number problem