[Tex/LaTex] Naming 3D axes in pgfplots

3dpgfplotstikz-pgf

I want to label the axes in a 3D plot with pgfplots. Using the anchors .right of origin and .above origin, I can label the axes as "x" and "y" in 2D with ease. In 3D, the labels must be tweaked to appear in the correct place, and I have no simple way of labeling the x-axis. Is there an anchor that directly relates to these positions? The MWE below shows what I've produced so far.

\begin{tikzpicture}
\begin{axis}%
[width=175pt,tick label style={font=\scriptsize},axis on top,
axis lines=center,
y dir=reverse,
name=myplot,
ymin=-1.1,ymax=1.1,
xmin=-1.1,xmax=1.1,
zmin=-1.1, zmax=1.1
]
\end{axis}
\node [right] at (myplot.right of origin)[shift={(-20pt,-8pt)}] {\scriptsize $y$};
\node [above] at (myplot.above origin) [shift={(0,-20pt)}] {\scriptsize $z$};
\end{tikzpicture}

enter image description here

Best Answer

With pgfplots, version 1.8, and

\pgfplotsset{compat=1.8}

it is possible to use the options

  • xlabel,
  • ylabel as well as
  • zlabel.

As you have reversed the direction of the y axis with

y dir=reverse

it is necessary to correct the position of every axis y label with

every axis y label/.append style={at=(ticklabel* cs:0)}

(previously (ticklabel* cs:1)).

In the example below, I have resized the whole plot so that it isn’t as cramped as before.

Code

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
  width=2*175pt,
  tick label style={font=\scriptsize},
  axis on top,
  axis lines=center,
  y dir=reverse,
  name=myplot,
  enlargelimits=.1,
  ymin=-1, ymax=1, xmin=-1, xmax=1, zmin=-1, zmax=1,
  xlabel=$x$, ylabel=$y$, zlabel=$z$,
  every axis y label/.append style={at=(ticklabel* cs:0)}]
\end{axis}
\end{tikzpicture}
\end{document}

Output

enter image description here

Related Question