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.

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

\addplot3 coordinates {(0,0,0) (0.5,-0.5,0.8)};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

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

\addplot3 coordinates {(0,0,0) (0.5,-0.5,0.8)};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

share|improve this question
    
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

1 Answer 1

up vote 5 down vote accepted

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             
    }
]
\addplot3 coordinates {(0,0,0) (0.5,-0.5,0.8)};
\end{axis}  
\end{tikzpicture}
\end{document}
share|improve this answer
    
nice workaround! I'll wait for Christian's feedback, otherwise I'll file the bug report. Thank you. –  Luigi Nov 27 '12 at 10:27
1  
That is a known bug ... –  Christian Feuersänger Nov 27 '12 at 15:22

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.