29

given the following code, I want to modify the tick labels in such a way, that for negative values of x, the labels are located above the x-axis. How can I realize this?

\documentclass{report}
\usepackage{pgf}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pgfplotsset{plot coordinates/math parser=false}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
axis x line=middle,
axis y line=middle,
width=10cm,
height=10cm,
scale only axis,
xmin=-5,
xmax=5,
xtick={-4, -2, 0,  2,  4},
xticklabels={$-4\pi$, $-2\pi$, $0$, $2\pi$, $4\pi$},
extra x ticks={-4, -2},
ymin=-1.4,
ymax=1.4,
ytick={-1,  0,  1}]
\end{axis}
\end{tikzpicture}%
\end{document}

1 Answer 1

33

Since you only need two different styles (as opposed to styles that differ for every label), you can use extra x ticks for the negative labels:

\documentclass{report}
\usepackage{pgf}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pgfplotsset{plot coordinates/math parser=false}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
axis lines*=middle,
width=10cm,
height=10cm,
scale only axis,
xmin=-5,
xmax=5,
xtick={2,  4},
xticklabels={$2\pi$, $4\pi$},
extra x ticks={-4, -2},
extra x tick labels={$-2\pi$, $-4\pi$},
extra x tick style={
    xticklabel style={yshift=0.5ex, anchor=south}
},
ymin=-1.4,
ymax=1.4,
ytick={-1,  0,  1}]
\end{axis}
\end{tikzpicture}%
\end{document}
2
  • 2
    Is there any solution for styles that differ for every label? Commented Nov 13, 2015 at 11:36
  • 2
    I would also be interested in styles differing for every label.
    – Olorun
    Commented Dec 23, 2015 at 7:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .