# How can I get even steps on x and y axes in a plot?

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?

• Look up AspectRatio. May 10, 2013 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. May 10, 2013 at 13:18
• Even if you set AspectRatio -> Automatic? May 10, 2013 at 13:21
• You are absolutely right! Automatic does indeed work! May 10, 2013 at 13:28
• Read up on what that option does, and then you can write an answer to your own question. :) May 10, 2013 at 13:29

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]
]


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


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.

• Crystal clear answer, I really appreciate it Sep 24, 2016 at 16:45

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]


• Sure! That's definitely a better way to do it. May 19, 2013 at 8:32