2
$\begingroup$

How can I modify the following code so that the vertical axes in both the graphics and plot align up? I think the aspect ratio for the plot is good. It appears that changing the ImageSize of the plot works, but I don't exactly what to change it to so that the vertical axes align exactly.

Manipulate[
  Grid[{
    {Graphics[{Circle[],Blue, PointSize[Large], Point[{Cos[θ], Sin[θ]}]},
       Axes -> True],
     Show[
       Plot[Sin[θ], {θ, 0, 2 Pi}, 
         Ticks -> {Range[0, 2 π, π/2], Automatic}, 
         PlotStyle -> Red],
       Graphics[
         {Blue, Line[{{θ, 0}, {θ, Sin[θ]}}], 
          PointSize[Large], Point[{θ, Sin[θ]}]}]]}},
    Frame -> All],
  {{θ, π/6}, 0, 2 Pi, Appearance -> "Labeled"}]

enter image description here

$\endgroup$
2
  • 5
    $\begingroup$ See, for instance, here. By the way, this is the first link that shows up in the Related links in the sidebar to the right. It is a good idea to search this site first for the answer to your question! $\endgroup$
    – march
    Commented Nov 22, 2015 at 22:51
  • $\begingroup$ Thanks. Using the accepted answer, I evaluated the padding function and I got my ip to be {21, 9}. However, it did not improve the vertical axes much. $\endgroup$ Commented Nov 22, 2015 at 23:17

3 Answers 3

3
$\begingroup$
plotrangeconditions = Sequence[PlotRange -> {-1, 1}, PlotRangePadding -> Scaled[.05]];

Manipulate[
 GraphicsGrid[
  {{
    Graphics[
     {Circle[], Blue, PointSize[Large], Point[{Cos[θ], Sin[θ]}]}, Axes -> True,
     (*Introduce explicit plotrange and padding*)
     plotrangeconditions
    ],
    Show[
     Plot[Sin[θ], {θ, 0, 2 Pi}, Ticks -> {Range[0, 2 π, π/2], Automatic}, PlotStyle -> Red], 
     Graphics[{Blue, Line[{{θ, 0}, {θ, Sin[θ]}}], PointSize[Large], Point[{θ, Sin[θ]}]}],
     (*Introduce same plotrange and padding*)
     plotrangeconditions,
     (*Select a size*)
     ImageSize -> Medium
    ]
    }},
  Frame -> All
 ],
 {{θ, π/6}, 0, 2 Pi, Appearance -> "Labeled"}
]

Mathematica graphics

$\endgroup$
1
  • $\begingroup$ Thanks. It seems that using GraphicsGrid and changing the ImageSize are the major factors here, and both seem to be required. Why does changing the ImageSize on only the second graphic make this work. Does GraphicsGrid make all have the same ImageSize somehow? $\endgroup$ Commented Nov 23, 2015 at 1:56
2
$\begingroup$
 Manipulate[
     Grid[{{
        Graphics[{Circle[], Blue, PointSize[Large], 
          Point[{Cos[\[Theta]], Sin[\[Theta]]}]},
         Axes -> True,
         ImagePadding -> 80,
         ImageSize -> 400],
        Show[
         Plot[Sin[\[Theta]], {\[Theta], 0, 2 Pi},
          Ticks -> {Range[0, 2 \[Pi], \[Pi]/2], Automatic},
          PlotStyle -> Red,
          ImageSize -> 400],
         Graphics[
          {Blue, Line[{{\[Theta], 0}, {\[Theta], Sin[\[Theta]]}}],
           PointSize[Large], Point[{\[Theta], Sin[\[Theta]]}]}]]}},
      Frame -> All],
     {{\[Theta], \[Pi]/6}, 0, 2 Pi, Appearance -> "Labeled"}]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thanks. I am curious how you came up with the 80 for ImagePadding and 400 for ImageSize. Both numbers seem to be important since changing either one loses the desired effect. Also, why not add the ImagePadding option to both graphics. I am just trying to understand how to use this technique again on a similar problem. $\endgroup$ Commented Nov 23, 2015 at 1:54
2
$\begingroup$

It seems to me that everybody is working too hard on this problem. It can be solved with a very simple GraphicRow expression in which the images in the row are forced to have the same height.

Manipulate[
  GraphicsRow[{
    Graphics[{Circle[], Blue, PointSize[Large], Point[{Cos[θ], Sin[θ]}]},
      ImageSize -> {Automatic, 150},
      Axes -> True],
    Plot[Sin[θ], {θ, 0, 2 Pi},
      ImageSize -> {Automatic, 150},
      Ticks -> {Range[0, 2 π, π/2], Automatic},
      PlotStyle -> Red,
      Epilog ->
       {Blue, Line[{{θ, 0}, {θ, Sin[θ]}}],
        PointSize[Large], Point[{θ, Sin[θ]}]}]},
    Frame -> All],
  {{θ, π/6}, 0, 2 Pi, Appearance -> "Labeled"}]

graphics

$\endgroup$
2
  • $\begingroup$ The OP asked for a method "so that the vertical axes in both the graphics and plot align up". Your vertical axes are very close, but they do not really line up perfectly. For instance, note that the right plot's vertical axis reaches up to 1.1, whereas the one in the left Graphics expression does not. In my opinion @eldo's answer suffers from the same problem. However, perhaps I'm reading too much in the OP's language. $\endgroup$
    – MarcoB
    Commented Nov 23, 2015 at 6:29
  • $\begingroup$ I wouldn't say you are reading too much into the problem. I would say that making the sure the corresponding y-values are at the same height is the most important thing. $\endgroup$ Commented Nov 24, 2015 at 0:43

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