[Tex/LaTex] TikZ: Replacing the values (labels) on x-axis with names

plottikz-pgf

I managed to create a simple linear plot with pgfplots-manual (chapter 4.5.1)

enter image description here

Now I want to replace the values of x-axis (1,2,3,4) with text, e.g.Test A, Test B, Test C, Test D. How can I do such a configuration?

MWE:

    \documentclass[12pt,ngerman]{article}
    \usepackage{pgfplots}
    \pgfplotsset{width=7cm,compat=1.10}

    \begin{document}

    \begin{tikzpicture}
    \begin{axis}
        [
        xlabel={Test},
        ylabel={Mean}
        ]
    \addplot+[sharp plot] coordinates
    {(0,18.26) (1,21.47) (2,24.58) (3,24.95)};
    \end{axis}
    \end{tikzpicture}

    \end{document}

Best Answer

You have to rename the already existing tick labels. Therefore you define the position of the ticks (one tick for each data point as seen below or ticks in a certain pattern as seen in the commented line) by xtick= and rename their labels by xticklabels=.

% arara: pdflatex

\documentclass[12pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}

\begin{document}
\begin{tikzpicture}
    \begin{axis}
        [
        ,width=7cm
        ,xlabel=Test
        ,ylabel=Mean
        ,xtick=data,
       %,xtick={0,1,...,3}
        ,xticklabels={Test A,Test B,Test C,Test D}
        ]
        \addplot+[sharp plot] coordinates
        {(0,18.26) (1,21.47) (2,24.58) (3,24.95)};
    \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Related Question