2

the following code does what I want in terms of xticklabels, however, I do not understand why I had to insert 5 xticklabels instead of only three including a phantom-label to achieve my goal. Is there a more elegant, comprehensible way?

    \begin{document}
    \usepackage{pgfplots}
    \begin{tikzpicture}
    \begin{axis}[
    axis x line=bottom,
    axis y line=left,
    grid=major, xmin=0, xmax=4,
    xticklabel style = {rotate=90, anchor=east},
    xticklabels = {0,\phantom{0},Chlor,Brom,Jod}
    ]
    \addplot[thick,dashed] coordinates { (0,20) (4,20) };
    \end{axis}
    \end{tikzpicture}
    \end{document}

enter image description here

  • 1
    When setting ticklabels manually, you should also set tick values yourself so that you control their position as well. – BambOo Sep 26 '19 at 15:23
3

See this example, note that in the second picture, there are not ticks at x=0 and x=4. If you want to leave a tick without ticklabel just leave an empty ,, in your ticklabels={...}.

\documentclass[tikz]{standalone} 
\usepackage{pgfplots}

\begin{document}
    \begin{tikzpicture}
    \begin{axis}[
    axis x line=bottom,
    axis y line=left,
    grid=major, xmin=0, xmax=4,
    xticklabel style = {rotate=90, anchor=east},
    xticklabels = {0,\phantom{0},Chlor,Brom,Jod}
    ]
    \addplot[thick,dashed] coordinates { (0,20) (4,20) };
    \end{axis}
    \end{tikzpicture}
    \begin{tikzpicture}
    \begin{axis}[
    axis x line=bottom,
    axis y line=left,
    grid=major, xmin=0, xmax=4,
    xticklabel style = {rotate=90, anchor=east},
    xtick={1,2,3},
    xticklabels = {Chlor,Brom,Jod}
    ]
    \addplot[thick,dashed] coordinates { (0,20) (4,20) };
    \end{axis}
    \end{tikzpicture}
    \begin{tikzpicture}
    \begin{axis}[
    axis x line=bottom,
    axis y line=left,
    grid=major, xmin=0, xmax=4,
    xticklabel style = {rotate=90, anchor=east},
    xtick={1,2,3},
    xticklabels = {Chlor,,Jod}
    ]
    \addplot[thick,dashed] coordinates { (0,20) (4,20) };
    \end{axis}
    \end{tikzpicture}
\end{document}

enter image description here

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.