1
$\begingroup$

I am trying to get a row of plots (which include legends and labels) using GraphicsRow, with vertical heights of the plots equal. I manually set the size and image padding of these plots so that the plots take up the same vertical space

verticalSize = 250;
p1 = Plot[Evaluate@Table[Cos[n x], {n, 1, 4}], {x, 0, 2 Pi}, 
           Frame -> True, RotateLabel -> False, PlotRange -> All, 
           PlotLegends -> 
           Placed [Map[StringReplace["n= x", "x" -> ToString[#, InputForm]] &,
           Table[n, {n, 1, 4}]], {Scaled[{0, 1}], {-0.1, 1.01}}], 
           Epilog -> Inset[Text[Style["(a)", 16]],
           ImageScaled[{0.9, 0.9}], Alignment -> Center], 
           ImageSize -> {Automatic, verticalSize}, 
           ImagePadding -> {{Automatic, Automatic}, {35, 4}}]

 p2 = Plot[Evaluate@Table[(1/(\[Sigma] Sqrt[
            2 Pi])) Exp[-0.5 (x/\[Sigma])^2], {\[Sigma], 1, 4}], {x,-10, 10},Frame -> True, 
        FrameLabel -> 
{"x", "\[LeftBracketingBar]\!\(\*SubscriptBox[\(
[CapitalPsi]\), \
\(0\)]\)(x; \[Sigma])\!\(\*SuperscriptBox[\(\[RightBracketingBar]\), \
\(2\)]\)"},                                       
            RotateLabel -> False, PlotRange -> All, 
            PlotLegends -> 
            Placed [Map[
            StringReplace["\[Sigma]= x", "x" -> ToString[#, InputForm]] &, 
            Table[n, {n, 1, 4}]], {Scaled[{0, 1}], {-0.1, 1.01}}],
            Epilog -> 
            Inset[Text[Style["(b)", 16]], ImageScaled[{0.9, 0.9}], 
            Alignment -> Center], ImageSize -> {Automatic, verticalSize}, 
            ImagePadding -> {{Automatic, Automatic}, {35, 4}}]

This produces plots

Mathematica graphics

Ideally, I want to see these exact images at the size I see in the output cell side-by-side in one graphic. However, when I come to using Graphics Row, the output shows that the overall image size and the image padding have been altered

Mathematica graphics

$\endgroup$

1 Answer 1

1
$\begingroup$

Shouldn't Row be enough for the job?

row = Row[{p1, p2}]

To export, simply type

Export["row.pdf",row]

enter image description here

You might want to move the labels in the second picture to RHS.

$\endgroup$
6
  • $\begingroup$ Sorry, I should have said: I then want to export the figure to pdf for use in a LaTex document $\endgroup$
    – oweydd
    Jul 18, 2018 at 13:29
  • $\begingroup$ Sure, it is straightforward. The output file should be a pdf with a vector graphic. $\endgroup$ Jul 18, 2018 at 13:56
  • $\begingroup$ Doing as you suggested gives this !Mathematica graphics . How can I export it and retain the Frame, ticks and relative positions of the plots? $\endgroup$
    – oweydd
    Jul 19, 2018 at 9:22
  • $\begingroup$ Interesting. In my case, this is the procedure I use all the time when using pdfs. No idea why in your case it does not work with pdfs (i'm using linux and windows). $\endgroup$ Jul 19, 2018 at 15:02
  • $\begingroup$ I'm using Mac and version 11.1.1, so perhaps that's it? $\endgroup$
    – oweydd
    Jul 20, 2018 at 11:31

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.