4

How can one have an axes labels (x and z near the axis) like this:

enter image description here

9

You can place the axis labels at the tip of the axis lines by setting

axis lines=middle,
xlabel=$x$, xlabel style={at=(current axis.right of origin), anchor=west},
ylabel=$y$, ylabel style={at=(current axis.above origin), anchor=south}

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    axis lines=middle,
    xlabel=$x$, xlabel style={at=(current axis.right of origin), anchor=west},
    ylabel=$y$, ylabel style={at=(current axis.above origin), anchor=south},
    xtick=\empty, ytick=\empty
]
\addplot [very thick, domain=0:10] {x+rnd};
\end{axis}
\end{tikzpicture}
\end{document}
  • How to align the labels next to the arrow tips if axis y line=left, and axis x line=bottom, is chosen instead of axis lines=middle, and the y-domain becomes negative, e.g. with \addplot [very thick, domain=-4:8] {x+rnd-3};? – kromuchi Sep 4 '14 at 7:14
  • 2
    @kromuchi: Sure! Set every axis x label/.style={at={(rel axis cs:1,0)}, anchor=west}, every axis y label/.style={at={(rel axis cs:0,1)}, anchor=south}. – Jake Sep 4 '14 at 7:23
  • 1
    Thanks! In the meantime I also figured out that every axis x label/.style={at={(current axis.south east)}, anchor=north}, (or with anchor=west depending what you want) would do the same. – kromuchi Sep 4 '14 at 7:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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