3
$\begingroup$

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

enter image description here

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.

$\endgroup$
4
  • 1
    $\begingroup$ 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 $\endgroup$
    – C. E.
    Commented Nov 16, 2018 at 20:59
  • $\begingroup$ OK @C.E., so the magic is understanding how ImagePadding works. Not too hard. Thanks. $\endgroup$
    – John Doty
    Commented Nov 16, 2018 at 22:54
  • $\begingroup$ Support for dual y-axis is a much-requested feature in the program (comes up at least monthly here). $\endgroup$
    – ktm
    Commented Nov 17, 2018 at 4:30
  • $\begingroup$ I have been asking Wolfram for this for twenty years. I may not live long enough. $\endgroup$ Commented Nov 17, 2018 at 21:43

2 Answers 2

4
$\begingroup$

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}]

enter image description here

$\endgroup$
3
$\begingroup$

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

As a starter ...

Quiet@Needs["LevelScheme`LevelScheme`"] (* 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

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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