Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm plotting the shortest distance from a point to a line using the following code

Show[Plot[1/2 x + 1/2, {x, -6, 7}], 
     ListPlot[{{4, -2.5}, {2, 1.5}}, Joined -> True, PlotMarkers -> Automatic]]

As this is the shortest line from the point to the line, the angle between the two lines should be 90 degrees. It doesn't show up like that in Mathematica, however, since the y-axis is incrementing in visually smaller steps than the x-axis.

How can I get Mathematica to automatically to use even steps on the two axes?

share|improve this question
1  
Look up AspectRatio. –  J. M. May 10 '13 at 13:14
    
I'm aware of AspectRatio, but it's not what I'm looking for. AspectRatio simply stretches the graphics but I'm fine with it's current size. –  paldepind May 10 '13 at 13:18
2  
Even if you set AspectRatio -> Automatic? –  J. M. May 10 '13 at 13:21
    
You are absolutely right! Automatic does indeed work! –  paldepind May 10 '13 at 13:28
    
Read up on what that option does, and then you can write an answer to your own question. :) –  J. M. May 10 '13 at 13:29

2 Answers 2

up vote 5 down vote accepted

To understand what is going on lets examine your initial plot. We assign it to the variable g:

g = Show[
       Plot[1/2 x + 1/2, {x, -6, 7}], 
       ListPlot[{{4, -2.5}, {2, 1.5}}, Joined -> True, PlotMarkers -> Automatic]
    ]

enter image description here

g // ImageDimensions

{360, 224}

The figure's aspect ratio is therefore:

#2/#1 & @@ ImageDimensions[g] // N

0.6222222222

which happens to be close to $\frac{2}{\sqrt{5}+1}\approx 0.6180339887$ or the reciprocal of the golden ratio. This ratio is widely considered as being aesthetically pleasing and is therefore the default aspect ratio for Mathematica's Plot function:

Options[Plot, AspectRatio]

{AspectRatio -> 1/GoldenRatio}

With AspectRatio->Automatic Mathematica sets the aspect ratio to the ratio of the plot ranges in x and y directions:

h = Show[
      Plot[1/2 x + 1/2, {x, -6, 7}], 
      ListPlot[{{4, -2.5}, {2, 1.5}}, Joined -> True, PlotMarkers -> Automatic],     
      AspectRatio -> Automatic
    ];

#2/#1 & @@ ImageDimensions[h] // N

0.5083333333

#2/#1 & @@ (Subtract @@@ PlotRange[h])

0.4999999796

(small difference caused by the discrete pixel size).

This choice causes the the plot space to be isotropic which is needed for a correct display of angles.

h

enter image description here

Note that the default aspect ratio for Graphics is:

Options[Graphics, AspectRatio]

{AspectRatio -> Automatic}

This makes sense as in most drawings we want an isotropic space.

share|improve this answer

This is really a comment, but it doesn't fit well into a comment box.

Since you say in your profile that you are a fan of minimalism, you might want to consider doing your plot this way:

Plot[1/2 x + 1/2, {x, -6, 7}, 
  Epilog -> Line[{{4, -2.5}, {2, 1.5}}], 
  AspectRatio -> Automatic]

enter image description here

share|improve this answer
    
Sure! That's definitely a better way to do it. –  paldepind May 19 '13 at 8:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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