# How to Set the Ratio of Units of the Axes in a 2D Plot?

Consider the following plot

Plot[{Sin[x]}, {x, 0, 2*Pi}, PlotRange -> {{0, 2*Pi}, {-1.05, 1.05}},
AxesLabel -> {x, y}, AxesOrigin -> {0, 0}]


It is evident that $1$ unit on the $y$ axis is not as the same length of $1$ unit on the $x$ axis. I want the ratio of these units to be one or any other desired value $r=\dfrac{y \,\, \text{axis unit}}{x \,\, \text{axis unit}}$.

I searched for how to determine the scaling of these units of the axes. I encountered this post and this one. But I could not find a nice answer explaining a simple way to do the job. Also, I couldn't find a nice example in the documentation. I just learned from documentation that

AspectRatio determines the ratio of PlotRange, not ImageSize.

So here is my question

What is a simple way to manually edit the ratio of the units of the axes?.

• Check AspectRatio option of various plotting functions... Mar 27, 2016 at 20:08
• @unlikely: I read those parts. :) I am afraid that this is not a solution or the explanation in the documentation is not enough! :) Mar 27, 2016 at 20:09
• Try option Plot[..., AspectRatio->Automatic] Mar 27, 2016 at 20:18
• @unlikely: Can you kindly write an answer with proper details. I have tried these things already and do not understand what is happening! Sorry but I am a beginner! :) Mar 27, 2016 at 20:25

To get 1:1 unit ratio you can use

Plot[{Sin[x]}, {x, 0, 2*Pi},
PlotRange -> {{0, 2*Pi}, {-1.05, 1.05}},
AxesLabel -> {x, y}, AxesOrigin -> {0, 0},
AspectRatio -> Automatic
]


To get for example 1:2 unit ratio you can use:

Plot[{Sin[x]}, {x, 0, 2*Pi},
PlotRange -> {{0, 2*Pi}, {-1.05, 1.05}},
AxesLabel -> {x, y}, AxesOrigin -> {0, 0},
AspectRatio -> 2*(1.05 + 1.05)/(2 Pi - 0)
]


As stated by @Sjoerd to define AspectRatio properly you should take into account the PlotRange as I did.

If you don't know in advance the PlotRange of your plot you can also use the following to get it after making an "hidden" plot:

g = Plot[{Sin[x]}, {x, 0, 2*Pi},
AxesLabel -> {x, y}, AxesOrigin -> {0, 0}
];
Show[g, AspectRatio -> 2 / Divide @@ (Subtract @@@ PlotRange[g])]

• This was the simple answer I was looking for! :) So the key sentence of documentation is AspectRatio determines the ratio of PlotRange, not ImageSize. Mar 27, 2016 at 20:36
• Thanks again. The last solution is interesting. :) Mar 27, 2016 at 20:41
pl = Plot[{Sin[x]}, {x, 0, 2*Pi},
PlotRange -> {{0, 2*Pi}, {-1.05, 1.05}}, AxesLabel -> {x, y},
AxesOrigin -> {0, 0}]


Determine the actual setting of the AspectRatio option used for this plot with AbsoluteOptions:

ar = AspectRatio /. AbsoluteOptions[pl, AspectRatio]
(* 0.618034 *)


The replacement (/.) takes care of converting the option rule to an actual number.

With the setting AspectRation->Automatic Mathematica scales this such that the units have a ratio of 1 when measured in figure dimensions:

plAutomatic =
Plot[{Sin[x]}, {x, 0, 2*Pi}, PlotRange -> {{0, 2*Pi}, {-1.05, 1.05}},
AxesLabel -> {x, y}, AxesOrigin -> {0, 0},
AspectRatio -> Automatic]


The aspect ratio used in this case is:

arAutomatic =
AspectRatio /. AbsoluteOptions[plAutomatic, AspectRatio]
(* 0.334225 *)


Plotting the plot with this value yields the same plot as with Automatic':

Show[pl, AspectRatio -> aut]


Now we have a value that we can scale. Here by a factor of 2:

Show[pl, AspectRatio -> 2 aut]


• @H.R. I removed my comments. For 3D: BoxRatios` Mar 27, 2016 at 20:52