3
$\begingroup$

Why such a comportment?

Look at those plots

 p1 = Plot[PDF[NormalDistribution[0, 1], x], {x, -4, 4}, 
  FillingStyle -> LightRed];
 p2 = Plot[PDF[NormalDistribution[0, 1], x], {x, -4, -1}, 
  Filling -> Bottom, FillingStyle -> LightYellow];
 p3 = Plot[PDF[NormalDistribution[0, 1], x], {x, 1, 4}, 
  Filling -> Bottom, FillingStyle -> LightYellow];
 p4 = Plot[PDF[NormalDistribution[0, 1], x], {x, -1, 1}, 
  Filling -> Bottom, FillingStyle -> LightRed];

If I ask MA for the following command

 Show[p1, p2, p3, p4]

it delivers

enter image description here

If I ask MA for the following command

 Show[p4, p2, p3, p1]

it now delivers

enter image description here

In both cases I do not obtain what I was expecting

$\endgroup$
  • 2
    $\begingroup$ I think this is related to the order of precedence for plot range. If you do Show[p4, p2, p3, p1, PlotRange -> All, AxesOrigin -> {0, 0}] then you will get your first graph again. Show inherits the graphics options of the first graphics object in the list. See the documentation for Show[] here $\endgroup$ – Dunlop Nov 2 '16 at 6:41
  • 1
    $\begingroup$ Dunlop is correct. If there is need for further explanation, what output did you expect? $\endgroup$ – C. E. Nov 2 '16 at 8:26
3
$\begingroup$

Filling is typically done either up to the bottom of the plot, or to the horizontal axis. The position of either of these (in plot coordinates) depends on the plot range. Once the filling is created, it becomes static and won't change to adapt to future changes in the plot range (e.g. due to Show). This is why the pink filling doesn't go all the way to the bottom in your first example.

In your case the plot range is automatically determined and differs for the four plots. The solution: Make sure that the object which determines the filling boundary (bottom frame or axis) is at the same position in all four.

I would use Filling -> Axis and AxesOrigin -> {0,0} in all four Plot commands.

Alternatively, use Filling -> Bottom and manually set PlotRange -> {0,0.5} or similar.

| improve this answer | |
$\endgroup$
2
$\begingroup$

Why not use RegionPlot:

pdf[x_] := PDF[NormalDistribution[], x]
Show[RegionPlot[{Abs[x] < 1 && 0 < y < pdf[x], 
   Abs[x] > 1 && 0 < y < pdf[x]}, {x, -4, 4}, {y, 0, 0.4}, 
  PlotStyle -> {LightRed, LightYellow}, BoundaryStyle -> None], 
 Plot[pdf[x], {x, -4, 4}]]

enter image description here

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.