9

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}
9

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

  • 1
    Additional problem: if my labels are too long, they overlap - is there a possible solution or do I have to use abbrevations? – Jens Jun 27 '14 at 15:39
  • 3
    you may enlarge the width or you rotate your labels (x tick label style={rotate=90,anchor=east}). – LaRiFaRi Jun 27 '14 at 15:40

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.