16

I've got three plots combined through Overlay:

Overlay[Table[Plot[PDF[NormalDistribution[0, ss], x], {x, -2, 2}, 
     Axes -> {True, False},
     Ticks -> None,
     PlotRange -> {All, {0, 2}}, 
     ImageSize -> 200], 
     {ss, {.2, .5, 1}}]]

Now I'd like to obtain something like this: overlaid plots with a shift

I tried to achieve that with the Alignment option but to no avail. Thanks in advance for any ideas.

mattek
  • 321
  • 2
  • 6

3 Answers3

19

This is the same as your code plus the horizontal lines and some formatting:

cornflowerBlue = RGBColor[0.392193, 0.584307, 0.929395];
plots = 
 Table[
  Show[
    Graphics[{LightGray, Thick,  Line[{{-2, 0}, {2, 0}}]}], (* the line *)
    Plot[PDF[NormalDistribution[0, ss], x], {x, -2, 2}, PlotRange -> All, PlotStyle -> Directive[Thick, cornflowerBlue]]], 
  {ss, {.2, .5, 1}}]

Now we translate each graphic as we assemble them:

Graphics@MapThread[
  Translate, 
  {First /@ plots, 
   Accumulate@ConstantArray[0.5 {1, -1}, Length[plots]] (* generate the shifts *)
  }]

Modify the 0.5 {1, -1} translation vector to control the relative translation of the figures.

There are two key points:

  • extracting the graphics primitives from the output of Plot using First
  • using Translate to position them

An advantage of this method is that unlike Overlay it generates an actual Graphics object which is easier to export to the correct size.

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
17

Maybe not exactly what you were looking for, but this reminded me of a plotting function I made recently, so here it is.

data = Table[{x, 
    PDF[NormalDistribution[0, ss], x]}, {ss, {1, .5, .2}}, {x, -2, 
    2, .01}];
data2polygon[list_, offset_] := 
  Module[{forward, backward, zeros, yvalues},
   zeros = PadRight[{}, Length[list]];
   yvalues = PadRight[{}, Length[list], offset];
   forward = Transpose[{list[[All, 1]], yvalues, list[[All, 2]]}];
   backward = Transpose[{Reverse[list[[All, 1]]], yvalues, zeros}];
   Polygon[Join[forward, backward]]];
ptable = Table[
   Graphics3D[{Opacity[0.25], data2polygon[data[[n]], n]}], {n, 
    Length[data]}];
Show[ptable, Boxed -> False]

When the result is spit out, it looks like this

enter image description here

But then you can change the viewing angle with your mouse and you end up with something similar to what you asked for:

enter image description here

And then you could take it farther to add more plots,

data = Table[{x, PDF[NormalDistribution[0, ss], x]}, {ss, 
    1, .1, -.1}, {x, -2, 2, .01}];
ptable = Table[
   Graphics3D[{Opacity[0.55], Red, EdgeForm[Blue], 
     data2polygon[data[[n]], .7 n]}], {n, Length[data]}];
Show[ptable, Boxed -> False]

enter image description here

edit: It would be nice to find a way to automatically label the different plots in that last image, I may try to do so sometime in the future.

Jason B.
  • 68,381
  • 3
  • 139
  • 286
6

Seems like a combination of Inset/Offset is the way to go:

plotTab = 
    Table[Plot[PDF[NormalDistribution[0, ss], x], {x, -2, 2}, 
    Axes -> {True, False}, 
    Ticks -> None, 
    PlotRange -> {All, {0, 2}}, 
    ImageSize -> 200], 
    {ss, {.2, .5, 1}}];

Graphics[Table[
    {Inset[plotTab[[ii]], Offset[{10*ii, -10*ii}, {0, 0}]]}, 
    {ii, Length[plotTab]}]]

enter image description here

Kuba
  • 136,707
  • 13
  • 279
  • 740
mattek
  • 321
  • 2
  • 6