2
$\begingroup$

I use the code below to produce a 3D plot next to a 2D plot, but cannot place the plots nicely. The output plot has a lot of empty space to the left of the 3D plot and very little empty space to the right. I played around with Spacings. In this way I could move the plots a bit closer together and the right plot further away from the right boundary of the image, but I cannot move the 3D plot more towards the left boundary of the image. How can I achieve a more equidistant arrangement (the output image should have a 4:3 aspect ratio)?

sur[p_List] := {p[[1]], p[[2]], p[[1]]^2 - p[[2]]^2};
surface = ParametricPlot3D[sur[{x, y}], {x, -1, 1}, {y, -1, 1},PlotRange -> {{-0.7, 0.7}, {-0.7, 0.7}, {-1.5, 1.5}}];
GraphicsRow[{Show[surface, Boxed -> False, ImageSize -> 500],Show[Plot[2*Sin[2*angle], {angle, 0, Pi}, AspectRatio -> (4/5),PlotRange -> {{-0.1, Pi + 0.1}, {-2.5, 2.5}}]]}]

enter image description here

$\endgroup$
2
  • $\begingroup$ Try placing the graphs inside a Graphics[ ] statement, where you can size them at will. The commands that place graphics automatically, like the GraphicsRow you use here, do not allow as much customization. $\endgroup$
    – Nicholas G
    Jan 29, 2021 at 22:44
  • $\begingroup$ @NicholasG You mean replacing GraphicsRow with Graphics? If I do that nothing is plotted anymore. $\endgroup$
    – 220284
    Jan 30, 2021 at 8:19

2 Answers 2

4
$\begingroup$

You can reduce the space between elements in a GraphicsRow using the option Spacings. In the present case, you could even use negative spacings, such as

sur[p_List] := {p[[1]], p[[2]], p[[1]]^2 - p[[2]]^2};
surface = 
  ParametricPlot3D[sur[{x, y}], {x, -1, 1}, {y, -1, 1}, 
   PlotRange -> {{-0.7, 0.7}, {-0.7, 0.7}, {-1.5, 1.5}}];

GraphicsRow[{
  Show[surface, Boxed -> False, ImageSize -> 500], 
  Show[Plot[2*Sin[2*angle], {angle, 0, Pi}, AspectRatio -> (4/5), 
    PlotRange -> {{-0.1, Pi + 0.1}, {-2.5, 2.5}}]]},
 Spacings -> -100]

Spacings is not the most conventient solution as AspectRatios are sometimes altered. Alternatively, you could use Inset, as in

Graphics[{
  Inset[surface, {-10, 0}], 
  Inset[Show[
    Plot[2*Sin[2*angle], {angle, 0, Pi}, AspectRatio -> (4/5), 
     PlotRange -> {{-0.1, Pi + 0.1}, {-2.5, 2.5}}]], {10, 0}]
  }]

The coordinate to Inset specifies where you want the sub-graph be placed. That should give you more flexibility.

$\endgroup$
3
  • $\begingroup$ Thanks! But all this seems to do is move the right plot more towards the center but the left remains where it is. I want to move the left plot more to the left as well. $\endgroup$
    – 220284
    Jan 30, 2021 at 8:15
  • $\begingroup$ @220284 I added a second solution with may offer what you are looking for. $\endgroup$ Jan 30, 2021 at 15:26
  • $\begingroup$ Many thanks! I wasn't aware of inset. $\endgroup$
    – 220284
    Jan 30, 2021 at 23:20
1
$\begingroup$

You can use Inset inside Graphics for precise placement, such as Graphics[{White, Rectangle[{0, 0}, {7, 5}], Inset[surface, Scaled[{.25, .5}], {.4, .5}, 5], Inset[linegraph, Scaled[{.65, .5}], {.5, 0}, 3]},(*Axes->False,*)AspectRatio -> 1/GoldenRatio] (You might need to un-rem the Axes to place them as you like), which produces this:

enter image description here

$\endgroup$
1
  • $\begingroup$ Many thanks for your help! $\endgroup$
    – 220284
    Jan 30, 2021 at 23:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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