# Stacking plots over common X axis

Is there a good way to stack plots that share a common X scale, but not a common Y scale? A toy example:

ts = Table[Sin[x/2.], {x, 0, 10}]
GraphicsColumn[{ListPlot[ts/100, Frame -> True,
FrameLabel -> {Null, "Stimulus"}],
ListPlot[ts, Frame -> True, FrameLabel -> {Null, "Response"}]}]

yielding

The X axes are redundant and don't even line up. Is there an easy way to combine these as separate frames above a single axis? In my real, more complicated problem, overlaying the plots is confusing as the points have a lot of scatter. Plotting them one above the other brings out the relationship better.

• This is difficult in Mathematica, because of this I believe (the fact that it hasn't got a working answer). Nevertheless, there are solutions to this type of problem here and here Commented Nov 16, 2018 at 20:59
• OK @C.E., so the magic is understanding how ImagePadding works. Not too hard. Thanks. Commented Nov 16, 2018 at 22:54
• Support for dual y-axis is a much-requested feature in the program (comes up at least monthly here).
– ktm
Commented Nov 17, 2018 at 4:30
• I have been asking Wolfram for this for twenty years. I may not live long enough. Commented Nov 17, 2018 at 21:43

This is my solution that I used in my figure: Play with ImagePadding if necessary.

ts = Table[Sin[x/2.], {x, 0, 10}];
Multicolumn[{ListPlot[ts/100, Frame -> True,
FrameLabel -> {Null, "Stimulus"},
FrameTicks -> {{True, False}, {False, False}}, ImageSize -> 400,
ImagePadding -> {{60, 2}, {1, 1}}],
ListPlot[ts, Frame -> True,
FrameTicks -> {{True, False}, {True, False}},
FrameLabel -> {Null, "Response"}, ImageSize -> 400,
ImagePadding -> {{60, 2}, {30, 1}}]}, 1, Spacings -> {0, 0}]

I'd use LevelScheme or its successor SciDraw for this.

As a starter ...

Quiet@Needs["LevelSchemeLevelScheme"] (* load package *)

Set up the figure ...

Block[{ts, mnx, mxx},
ts = Table[Sin[x/2.], {x, 0, 10}];
{mnx, mxx} = {1, Length@ts};
Figure[{
SetOptions[SchemeObject, FontFamily -> "Helvetica", FontSize -> 10],
ScaledLabel[{.5, .97}, "Test", FontSize -> 12, FontWeight -> Bold,
Offset -> {0, 0}],
Multipanel[{2, 1},
Margin -> 50,
XPlotRanges -> {mnx, mxx},
YPlotRanges -> {{-.01, .01}, {-1, 1}},
XFrameLabels -> {""}, BufferB -> 5,
YFrameLabels -> {"Stimulus", "Response"}, BufferL -> 7.5,
XFrameTicks -> {LinTicks[1, 11, 2, 2]},
YFrameTicks -> {LinTicks[-.01, .01, .005, 1],
LinTicks[-1, 1, .5, 1]},
YGapSizes -> .1, XGapSizes -> .05,
YPanelSizes -> {1, 1},
XPanelSizes -> {1},
First -> "A", Order -> Vertical],
FigurePanel[{1, 1}],
RawGraphics@ListPlot[ts/100, PlotStyle -> Black],
FigurePanel[{2, 1}],
RawGraphics@ListPlot[ts, PlotStyle -> Black]
},
ImageSize -> 500]
]

to produce