# pgfplots: labels and width issues in non-boxed 3d plot with oblique projection

## Update april 2013

The bug has been fixed with pgfplots version 1.8 (requires \pgfplotsset{compat=1.8}).

When I try to add the axes labels to this code, I get a division by zero error. I think the error is responsive to the choice of the unit vectors directions (see after).

\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$},
]

\end{axis}
\end{tikzpicture}
\end{document}


Now look at this code with a different choice of unit vectors. The axes labels are drawn (I get no error), but far away from their axis and overlapped. Moreover, the actual width is about 5 cm and not 10 cm as it should be (scale only axis won't help here).

\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$},
]

\end{axis}
\end{tikzpicture}
\end{document}


-
Interesting.. The divide by 0 must be coming from some calculation that is begin done to determine where the axis labels are to be placed. The only solution I can come up is not very ideal, and that is to manually place the axis labels: \node at (axis cs: 0.85,0,0) {$x$}; \node at (axis cs: 0,0.30,0) {$y$}; \node at (axis cs: 0,0,0.85) {$z$};. –  Peter Grill Nov 27 '12 at 10:02
About the width issue: When you provide the unit vectors, the width and height keys have no effect, because the dimensions of the plot are already determined by the axis ranges and the unit vectors. –  Jake Nov 27 '12 at 10:15
@Jake, this isn't totally true. If you double the width, you'll see that the actual width doubles too, even if its dimension is wrong. –  Luigi Nov 27 '12 at 10:25
@Luigi: Ah yes, you're right. Hm, another weird behaviour. –  Jake Nov 27 '12 at 10:28

That is indeed strange behaviour regarding the placement of the labels. You might want to file a bug report for this. In the meantime, you can work around this by redefining the relevant label styles using something like

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
}
]