
我想設定縱橫比pgfplots 的繪圖沒有明確指定寬度和高度(即,保留預設值)。對於 3D 繪圖,有plot box ratio
;對於 2D 繪圖,我嘗試使用\axisdefaultheight
,但它只是讓事情變得不成比例:
\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}
此選項unit vector ratio
考慮了實際的軸限制,因此經過一些計算後,可以使用它。不過,我只是在尋找軸長度的設定。
有什麼提示嗎?
答案1
\axisdefaultheight
不是一個長度,而只是一個宏,這就是為什麼2\axisdefaultheight
不起作用,但卻2*\axisdefaultheight
有效的原因。但指定寬度和高度可能是最簡單的選擇。
\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}