4
$\begingroup$

I have been working on a problem where I wanted to stack multiple graphs on top of each other in the following format

The expected output

I tried to look for solutions to do the same but I could not. The closest I could get to was the Graphics command but in that case, there was undesired spacing between the graphs. Since all my graphs have the same values in the horizontal axis this looks a lot better. I understand the concepts of frames and my only issue is the spacing and alignment between the graphs. Is the solution to reduce the space in the Graphics command or there another solution?

Thank you to every suggestion or recommendation towards this.

$\endgroup$
1
  • $\begingroup$ Isn’t there an option for this now? $\endgroup$
    – user5601
    Sep 29, 2020 at 21:35

4 Answers 4

5
$\begingroup$

https://resources.wolframcloud.com/FunctionRepository/resources/PlotGrid

ResourceFunction[
        "PlotGrid"][{{Plot[Sin[x], {x, 0, 1}, Frame -> True, 
                FrameLabel -> {None, x}]}, {Plot[Cos[x], {x, 0, 1}, Frame -> True,
                    FrameLabel -> {None, x}]}}, FrameLabel -> {2 Pi t, None}]

enter image description here

$\endgroup$
4
$\begingroup$

Simply use Column:

pl = Plot[Sin[x], {x, 0, 2 Pi}];
Column[{pl, pl}, Frame -> All, Spacings -> 0]

enter image description here

$\endgroup$
2
  • $\begingroup$ Can you do it as a frame with ticks as shown in the OP? $\endgroup$
    – Michael E2
    Sep 29, 2020 at 19:29
  • $\begingroup$ You can e.g. try: pl = Plot[Sin[x], {x, 0, 2 Pi}, PlotTheme -> "Detailed"]; Column[{pl, pl}, Frame -> All, Spacings -> 0] Note, "Column" is not responsible for the ticks, it is the Plot function who does it. $\endgroup$ Sep 29, 2020 at 19:52
3
$\begingroup$

Here is one way where you can control the size along x and y of each subfigure

plot1 = With[{XZ = 210, YZ = 70}, 
   Plot[Sin[x], {x, -2 \[Pi], 2 \[Pi]}, Frame -> True, 
    ImageSize -> Automatic -> {XZ, YZ}, ImagePadding -> 80, 
    PlotStyle -> Red, Axes -> False]];
Grid[{{plot1}, {plot1}, {plot1}}, Spacings -> {-12, -12}]  

enter image description here

and you can do even more with this approach such as this configration

plotver = 
  With[{XZ = 70, YZ = 218}, 
   Plot[x, {x, -2 \[Pi], 2 \[Pi]}, Frame -> True, 
    ImageSize -> Automatic -> {XZ, YZ}, ImagePadding -> 80, 
    PlotStyle -> Red, Axes -> False]];
Grid[{{g, plotver}}, Spacings -> {-11, -12.}, 
 BaselinePosition -> Bottom]   

enter image description here

and have a look at this might help further

$\endgroup$
2
$\begingroup$

This use of ImagePadding works on a simple example:

pTop = Plot[Sin[x], {x, 0, 2 Pi}, Frame -> True, Axes -> False, 
   ImagePadding -> {{All, All}, {0, All}}];
pMid = Plot[Sin[x], {x, 0, 2 Pi}, Frame -> True, Axes -> False, 
   ImagePadding -> {{All, All}, {0, 0}}];
pBot = Plot[Sin[x], {x, 0, 2 Pi}, Frame -> True, 
   ImagePadding -> {{All, All}, {All, 0}}, Axes -> False];
Column[{pTop, pMid, pBot}, Spacings -> 0]

Often the vertical scales require different numbers of digits, which in turn leads to different paddings used to display the plots. As far as I know, this is most easily dealt with by setting the left ImagePadding through trial and error.

lMargin = Scaled[0.05];
pTop = Plot[Sin[x], {x, 0, 2 Pi}, Frame -> True, Axes -> False, 
   ImagePadding -> {{lMargin, All}, {0, All}}];
pMid = Plot[10 Sin[x], {x, 0, 2 Pi}, Frame -> True, Axes -> False, 
   ImagePadding -> {{lMargin, All}, {0, 0}}];
pBot = Plot[100 Sin[x], {x, 0, 2 Pi}, Frame -> True, 
   ImagePadding -> {{lMargin, All}, {All, 0}}, Axes -> False];
Column[{pTop, pMid, pBot}, Spacings -> 0]
$\endgroup$

Your Answer

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

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