0
$\begingroup$

I have two graphs and I want to have the ratio of the units on the horizontal and vertical axes be the same. I do not want to use AspectRatio->Automatic because the vertical dimension would be too small. Here is some sample code:

egl = {Line[{
     {0, .1}, {2, .3}}],
   Line[{
     {1.5, -.23}, {1.5, .7}}]};
g1 = Graphics[
   egl,
   Axes -> True,
   AspectRatio -> .5,
   PlotRange -> {{0, 2}, {0, .25}}]
g2 = Graphics[
   egl,
   Axes -> True,
   AspectRatio -> 1.5]
$\endgroup$

1 Answer 1

1
$\begingroup$

You have to define PlotRange as well. In your first example you made at this point a mistake.

g1 = Graphics[egl, Axes -> True, AspectRatio -> 0.25/2, PlotRange -> {{0, 2}, {0, .25}}]

More general:

pRange = {{0, 2}, {0, .25}}
g1e = Graphics[egl, Axes -> True, AspectRatio -> 1/Divide @@ Flatten[Differences /@ pRange], PlotRange -> pRange]

The second example should be like that:

g2 = Graphics[egl, Axes -> True, PlotRange -> {{0, 2}, {-1, 1}}, AspectRatio -> 1]

enter image description here

When you use AspectRatio -> 1 then the intervalls have to be equal. Means:

Differences@{0,2} == Differences@{-1,1}
(* True *)

Why do you use Show?

$\endgroup$
1
  • $\begingroup$ Many thanks, I accepted the answer. I use show because I have been using Mathematica since version 2.0. I'll try to drop it. $\endgroup$
    – Nicholas G
    Commented Oct 27, 2016 at 10:43

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.