3

I would like to set the aspect ratio of a pgfplots plots without explicitly specifying width and height (i.e., leaving them default). For 3D plots, there is plot box ratio; for 2D plots, I tried playing with \axisdefaultheight, but it just blows the thing out of proportion:

\documentclass{standalone}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}
\begin{tikzpicture}

\begin{axis}[
xmin=0.0, xmax=3.0,
ymin=0.0, ymax=1.0,
scale only axis,
width=2\axisdefaultheight
]
\addplot [red]
table {%
0 0
0.1 0.587785252292473
0.2 0.951056516295154
0.3 0.951056516295154
0.4 0.587785252292473
0.5 1.22464679914735e-16
0.6 -0.587785252292473
0.7 -0.951056516295154
0.8 -0.951056516295154
0.9 -0.587785252292473
1 -2.44929359829471e-16
1.1 0.587785252292474
1.2 0.951056516295154
1.3 0.951056516295154
1.4 0.587785252292473
1.5 3.67394039744206e-16
1.6 -0.587785252292473
1.7 -0.951056516295154
1.8 -0.951056516295154
1.9 -0.587785252292473
};
\end{axis}

\end{tikzpicture}
\end{document}

enter image description here

The option unit vector ratio takes into account the actual axis limits, so after a bit of computation, this could be used. I'm looking for a setting on the axis lengths only, though.

Any hints?

  • I think you can just add unit vector ratio = {16 3}. – Raaja Mar 18 at 11:05
1

\axisdefaultheight is not a length but just a macro, which is why 2\axisdefaultheight does not work, but 2*\axisdefaultheight works. But then it is probably the simplest option to specify both the width and height.

\documentclass{standalone}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=0.0, xmax=3.0,
ymin=0.0, ymax=1.0,
scale only axis,
height=\axisdefaultheight,
width=2*\axisdefaultheight
]
\addplot [red]
table {%
0 0
0.1 0.587785252292473
0.2 0.951056516295154
0.3 0.951056516295154
0.4 0.587785252292473
0.5 1.22464679914735e-16
0.6 -0.587785252292473
0.7 -0.951056516295154
0.8 -0.951056516295154
0.9 -0.587785252292473
1 -2.44929359829471e-16
1.1 0.587785252292474
1.2 0.951056516295154
1.3 0.951056516295154
1.4 0.587785252292473
1.5 3.67394039744206e-16
1.6 -0.587785252292473
1.7 -0.951056516295154
1.8 -0.951056516295154
1.9 -0.587785252292473
};
\end{axis}

\end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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