[Tex/LaTex] Text projection onto plane in 3D pgf plots

pgfplotstikz-pgf

I'd like to have text that appears as though it's written "on" one of the walls of a 3D tikz plot. MWE:

\documentclass{standalone}

\usepackage{tikz,pgfplots}
\usetikzlibrary{positioning,3d}
\pgfplotsset{compat=1.10}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    view={60}{30},
    %axis equal,
    clip=false,
    xmin=0,xmax=1,
    ymin=0,ymax=1,
    zmin=0,zmax=1,
    ]

    %\addplot3 (1,1,1);

    \path (axis cs:0,0,0) -- (axis cs:0,1,0) node[midway,above, sloped,xslant=0.2] {Text};

\end{axis}
\end{tikzpicture}

\end{document}

MWE1

The thing that I'm not happy with in this case is that I needed to set xslant manually. I could calculate it based on geometry, but pgfplots angles seem to not always be as you would expect. Example:

\documentclass{standalone}

\usepackage{tikz,pgfplots}
\usetikzlibrary{positioning,3d}
\pgfplotsset{compat=1.10}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    view={45}{90},
    %axis equal,
    clip=false,
    xmin=0,xmax=1,
    ymin=0,ymax=1,
    zmin=0,zmax=1,
    ]

    %\addplot3 (1,1,1);

    \path (axis cs:0,0,0) -- (axis cs:0,1,0) node[midway,above, sloped,xslant=0.2] {Text};

\end{axis}
\end{tikzpicture}

\end{document}

MWE2

[this is exactly he same as the previous example except that I've changed the view]. This gives a view of the plot from directly above, showing that the x and y axes are not perpendicular. I think that this can be changed with axis equal or axis equal image, but I'd rather not use those as they have side-effects.

I assume that pgfplots has internally calculated how the x, y, and z direction vectors are mapped to the 2-D page… is there a way that I can extract this information? If I had that available, then it would be easy to find the appropriate slope using trig. This would work without axis equal or axis equal image

Best Answer

I wasn't sure whether you wanted flat or vertical letters, so I did both. Note the use of [scale mode=scale uniformly]. Also note that yscale is the denominator of xslant, and xscale is the denominator of yslant.

text in 3d

\documentclass{standalone}

\usepackage{tikz,pgfplots}
\usetikzlibrary{positioning,3d}
\pgfplotsset{compat=1.10}

\begin{document}

\begin{tikzpicture}
\def\h{80}% horizontaql viewing angle
\def\v{10}% vertical viewing angle
\begin{axis}[
    scale mode=scale uniformly,
    view={\h}{\v},
    clip=false,
    xmin=0,xmax=1,
    ymin=0,ymax=1,
    zmin=0,zmax=1,
   ]
  \pgfmathparse{atan(tan(\h)*sin(\v))}
  \let\a=\pgfmathresult
  \pgfmathparse{atan(tan(90-\h)*sin(\v))}
  \let\b=\pgfmathresult  

    \path (axis cs:0,0,0) -- (axis cs:0,1,0) node[color=blue,midway,above,sloped,
    xslant=tan(\a+\b+90),yscale=sin(\a+\b)] {Text};

    \path (axis cs:0,0,0) -- (axis cs:0,1,0) node[color=red,midway,above,
    yslant=tan(\b),xscale=cos(\b)] {Text};

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

do the math