Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question
5  
Offset might be what you need. –  Verbeia Jan 16 at 19:26
    
Is this a one-shot deal? If so, just using drawing tools to combine/align is easiest. Otherwise, Inset or ImageCompose are possibilities. –  rasher Jan 16 at 23:13

3 Answers 3

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.

share|improve this answer

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.

share|improve this answer
    
This cobalt looks great but I can't reproduce it, it is significantly darker on my screen :/. –  Kuba Feb 21 at 0:34
    
@Kuba Fixed now. I tend to use the NamedColorsPalette[] from the SciDraw package. I think these may have come with some older version of Mathematica, but I'm not sure. –  Szabolcs Feb 21 at 0:56
    
@Kuba Yes, it's this one where the colours came from, I think the NamedColors package just added a palette to make it easy to choose a pretty one. –  Szabolcs Feb 21 at 0:58
    
Indeed, thank you ;) –  Kuba Feb 21 at 1:01

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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