[Tex/LaTex] Tikz axis width and height keys do not get correct aspect ratio

axisheightpgfplotstikz-pgfwidth

I have a problem when I try to set width and height of the axis environment in a tikzpicture. Consider the following MWE:

\documentclass{standalone}

\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
    \begin{axis}[
            xmin=0, xmax=2,
            ymin=0, ymax=3,
            width=2\textwidth,
            height=3\textwidth,
            xmajorticks=false,
            ymajorticks=false,
            xmajorgrids,
            ymajorgrids,
        ]
    \end{axis}
\end{tikzpicture}

\end{document}

Why is it that with this code the output figure has indeed aspect ratio (close to) 3:2:

enter image description here

but if I change the lines

width=2\textwidth,
height=3\textwidth,

to

width=2\textwidth,
height=3\textwidth,

the output I get is skewed (the aspect ratio is something around 2.5:1) (which, btw, can also be seen by the fact that the grid lines no longer create squares but rectangles)

enter image description here

I tried reading the manual, but I didn't find anything (I probably didn't look for the right keyword).

What am I missing?

EDIT

sorry, I shouldn't post when it's this late. What I meant to write was:
but if I change the lines

width=2\textwidth,
height=3\textwidth,

to

width=0.2\textwidth,
height=0.3\textwidth,

the output I get is skewed.

And actually, this applies to any other number, for that matter. If I keep the aspect ratio fixed but change the absolute values for width and height, the resulting picture will be more skewed the smaller the values I use

Sorry again for the troubles.

Best Answer

I found the solution. It was clearly stated in the pgfplots manual, it was just a matter of finding it:

Please note that pgfplots only estimates the size needed for axis- and tick labels. The estimate assumes a fixed amount of space for anything which is outside of the axis box. This has the effect that the final images may be slightly larger or slightly smaller than the prescribed dimensions. However, the fixed amount is always the same; it is set to 45pt. That means that multiple pictures with the same target dimensions will have the same size for their axis boxes – even if the size for descriptions varies. It is also possible to scale the axis box to the prescribed width/height. In that case, the total width will be larger due to the axis descriptions. However, the axis box fills the desired dimensions exactly. [...] If scale only axis is enabled, width and height apply only to the axis rectangle. Consequently, the resulting figure is larger that width and height (because of any axis descriptions). However, the axis box has exactly the prescribed target dimensions. If scale only axis=false (the default), pgfplots will try to produce the desired width including labels, titles and ticks.

So, to have the proper aspect ratio for all sizes, simply add scale only axis to the option keys for the axis environment.