0
$\begingroup$

Possible Duplicate:
Vertically aligning two separate plots

Trying to illustrate the sums of functions, high school math class... Found a great demonstration on interference patterns, so used some ideas from there. At this point, students are GRAPHICALLY simply plotting points on the two functions, then adding the function values to produce a third function that is the sum of the two given functions.

Below, a long command to set things up nicely for a plot on a piece of paper, with a blank grid for students to fill in.

t = 1; freq1 = 1; freq2 = 1.2;
start = -6;
finish = 6;
inc = 0.5;

pts1 = Table[{i, Sin[freq2 i - t]}, {i, start, finish, inc}];
pts2 = Table[{i, Sin[freq1 i + t]}, {i, start, finish, inc}];
pts3 = Table[{i, Sin[freq2 i - t] - Sin[freq1 i + t]}, {i, start, 
    finish, inc}];

Grid[{
  {
   Plot[{Sin[freq1 x + t], Sin[freq2 x - t]}, {x, -2 \[Pi], 2 \[Pi]},
    PlotStyle -> {Thin, Thick},
    PlotRange -> {-1.1, 1.1},
    GridLines -> {Range[-6, 6, 0.5], Range[-1, 1, 0.5]},
    GridLinesStyle -> GrayLevel[0.7],
    ImageSize -> {500, 200},
    AspectRatio -> 2/5, 
    Epilog -> {PointSize[0.015],  Point /@ pts1, Point /@ pts2}]},

  {Plot[Sin[freq2 x - t] - Sin[freq1 x + t], {x, -2 \[Pi], 2 \[Pi]},
    PlotStyle -> Opacity[0],
    PlotRange -> {-2, 2},
    GridLines -> {Range[-6, 6, 0.5], Range[-2, 2, 0.5]},
    GridLinesStyle -> GrayLevel[0.7],
    ImageSize -> {500, 200},
    AspectRatio -> 2/5,
     Epilog -> {PointSize[0.015],  Point /@ pts3}]}
  }]

Plot some points, connect the dots, voila... (I know , not too exciting!)

final plot

My question, is there any way to get those grids to line up perfectly along the horizontal axis. I know, it's trivial, and I'm happy with what I have at this point, but I would think there would be some way.... Yes, I tried working with the PlotRange but I was unable to make that work.

Suggestions are appreciated.

$\endgroup$
  • 3
    $\begingroup$ This is a duplicate of this one (see my answer there). You'll have to also fix the ImagePadding (and perhaps PlotRangePadding). The slightly different paddings are because one has thick lines and the other doesn't. $\endgroup$ – rm -rf Nov 8 '12 at 16:01
  • $\begingroup$ Thank you, that did just what I needed . $\endgroup$ – Tom De Vries Nov 8 '12 at 16:13

Browse other questions tagged or ask your own question.