Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to add a second labeling to my 3d plot, but I can not figure out how to do it correctly. The idea is to add a second axis without any grid, ticks, lines and nothing but labels and overlay it over the first plot. However, I seem not to be able to

  1. Place the second axis labels correctly and
  2. Make the second axis invisible except for its labels.

This is a short example of what I do:

\begin{tikzpicture}  

% This is the plot itself  
\begin{axis}[domain=-1:1,view={135}{45},xlabel style={sloped},ylabel style={sloped},zlabel style={sloped},xlabel=$x$,ylabel=$y$,zlabel=$z$]  
  \addplot3[] coordinates {(1,0,0) (0,0,1)};  
\end{axis}  

% This is the invisible plot that should only add labels to the first plot  
\begin{axis}[domain=-1:1,view={135}{45},grid=none,xlabel style={sloped},ylabel style={sloped},xlabel=$X$,ylabel=$Y$,xtick=\empty,ytick=\empty,ztick=\empty,axis z line=none,x axis line style={transparent},y axis line style={transparent}]  
   \addplot3[mark=none] coordinates {(0,0,0)}; % for a correct viewing angle  
\end{axis}

\end{tikzpicture}

I attached a file that shows what I actually get and implies (in red) what I try to get. It is not good to see in this example, but transparency does not work as expected, the lines of the second "invisible" plot are still clearly visible and naturally drawn on top of the first plot.

My picture: Black is what I have, red is what I would like to have. enter image description here

I would be glad if anyone had an idea how to fix this. Or maybe there is a totally different way how this can be achieved.

share|improve this question
    
Welcome to TeX.sx! Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Upvoting is the preferred way here to say "thank you" to users who helped you. Also, I uploaded your image using the official stackexchange interface, i.e. the image icon on top of the text field, and added it to the post. This ensures that all images are always accessible and do not expire. –  Torbjørn T. Nov 14 '11 at 15:42
add comment

2 Answers

Torbjorn's solution already has the correct placement. The rotation can be achieved by means of sloped like x axis and its variants:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}  
\begin{axis}[domain=-1:1,view={135}{45},
    xlabel style={sloped},
    ylabel style={sloped},
    zlabel style={sloped},
    xlabel=$x$,
    ylabel=$y$,
    zlabel=$z$,
    clip=false]  
  \addplot3[mark=none] coordinates {(1,0,0) (0,0,1)};  
  \node at (rel axis cs:0,0.5,1) [above,sloped like y axis] {a long $x$ label};
  \node at (rel axis cs:0.5,0,1) [above,sloped like x axis] {a long $y$ label};
\end{axis}  
\end{tikzpicture}
\end{document}

enter image description here

Note that sloped is actually an alias to one of the sloped like x axis variants inside of an axis.

share|improve this answer
add comment

You could use the rel axis cs coordinate system and add the labels manually.

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}  
\begin{axis}[domain=-1:1,view={135}{45},xlabel style={sloped},ylabel style={sloped},zlabel style={sloped},xlabel=$x$,ylabel=$y$,zlabel=$z$,clip=false]  
  \addplot3[mark=none] coordinates {(1,0,0) (0,0,1)};  
  \node at (rel axis cs:0,0.5,1) [above,rotate=-25] {$X$};
  \node at (rel axis cs:0.5,0,1) [above,rotate=25] {$Y$};
\end{axis}  
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
Thank you, this is a really smart solution. However, the rotation of X and Y does not seem to fit to the angle of the top axes correctly. For a longer expression, one can clearly see that the formulas and the axes are not parallel. Is there a better way than shifting the rotation values until it looks good? PS: A value of +/- 30 degree seems to fit perfectly. –  Bernd Nov 14 '11 at 17:20
    
@Bernd Not that I know, but then I hardly know my way around pgfplots. Give it some time though, and there's a good chance someone with a better solution reads the question. –  Torbjørn T. Nov 14 '11 at 17:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.