2013 年 4 月更新
该错误已在pgfplots
1.8 版中修复(需要\pgfplotsset{compat=1.8}
)。
当我尝试将轴标签添加到此代码时,出现错误division by zero
。我认为错误与单位向量方向的选择有关(见下文)。
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7} % *EDIT*: this improves scale uniformly.
\begin{document}
\begin{tikzpicture}
\begin{axis}[axis lines=center,
% *EDIT*: this here respects your choice of unit vectors.
% scale uniformly computes one common scaling factor
% and chooses limits such that the image fulfills the
% prescribed width/height as best as possible.
x={(-0.3535cm,-0.3535cm)}, y={(1cm,0cm)}, z={(0cm,1cm)},
scale mode=scale uniformly,
xlabel={$x$}, ylabel={$y$}, zlabel={$z$},
]
\addplot3 coordinates {(0,0,0) (0.5,-0.5,0.8)};
\end{axis}
\end{tikzpicture}
\end{document}
现在看看这个代码,使用不同的单位向量选择。轴标签已绘制(我没有收到错误),但远离轴且重叠。此外,实际宽度约为 5 厘米,而不是应有的 10 厘米(scale only axis
这里没有帮助)。
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7} % *EDIT*: this improves scale uniformly.
\begin{document}
\begin{tikzpicture}
\begin{axis}[width=10cm,
axis lines=center,
xmin=0, xmax=1, ymin=-1, ymax=1, zmin=0, zmax=1,
% *EDIT*: this here respects your choice of unit vectors.
% scale uniformly computes one common scaling factor
% and chooses limits such that the image fulfills the
% prescribed width/height as best as possible.
x={(0.94cm,-0.34cm)}, y={(0.766cm,0.643cm)}, z={(0cm,1cm)},
scale mode=scale uniformly,
xlabel={$x$}, ylabel={$y$}, zlabel={$z$},
]
\addplot3 coordinates {(0,0,0) (0.5,-0.5,0.8)};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
这确实是标签放置方面的奇怪行为。您可能需要提交错误报告解决此问题。与此同时,您可以通过重新定义相关标签样式来解决此问题,例如
every axis x label/.style={
at={(axis cs:\pgfkeysvalueof{/pgfplots/xmax},0,0)},
xshift=-1em
},
every axis y label/.style={
at={(axis cs:0,\pgfkeysvalueof{/pgfplots/ymax},0)},
yshift=2ex,
},
every axis z label/.style={
at={(axis cs:0,0,\pgfkeysvalueof{/pgfplots/zmax})},
xshift=1em
}
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7}
\begin{document}
\begin{tikzpicture}
\begin{axis}[axis lines=center,
x={(-0.3535cm,-0.3535cm)}, y={(1cm,0.0cm)}, z={(0cm,1cm)},
scale mode=scale uniformly,
xlabel=$x$, ylabel=$y$, zlabel=$z$,
every axis x label/.style={
at={(axis cs:\pgfkeysvalueof{/pgfplots/xmax},0,0)},
xshift=-1em
},
every axis y label/.style={
at={(axis cs:0,\pgfkeysvalueof{/pgfplots/ymax},0)},
yshift=2ex,
},
every axis z label/.style={
at={(axis cs:0,0,\pgfkeysvalueof{/pgfplots/zmax})},
xshift=1em
}
]
\addplot3 coordinates {(0,0,0) (0.5,-0.5,0.8)};
\end{axis}
\end{tikzpicture}
\end{document}