2

I am trying to create a bar chart with pgfplots. My code is similar to example :

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
  \begin{figure}[h!]
    \begin{tikzpicture}
      \begin{axis}[
        ybar,
        enlargelimits=0.15,
        legend style={at={(0.5,-0.15)},anchor=north,legend columns=-1},
        ylabel=something,
        symbolic x coords={tool8,tool9,tool10},
        xtick=data,
        nodes near coords,
        nodes near coords align={vertical}]
        \addplot coordinates {(tool8,7) (tool9,9) (tool10,4)};
        \addplot coordinates {(tool8,4) (tool9,4) (tool10,4)};
        \addplot coordinates {(tool8,1) (tool9,1) (tool10,1)};
        \legend{used,understood,not understood}
      \end{axis}
    \end{tikzpicture}
    \caption[TODO]{TODO}
    \label{label}
  \end{figure}
\end{document}

I get the error:

finished with exit code 1.

  • Does that code give a bar chart if you run it?
  • What could be the reason that it does not work for me?
  • Wrong pgfplots version?

My output looks like this:

image

For each entry in coordinates I get

Package PGF Math Error: Could not parse input 'tool8' as a floating point number, sorry. The unreadable part was near 'tool8'..

I use Xubuntu 12.04 with Kile 2.1.0 and \pgfversion 2.10

Update:

If I remove the symbolic x coords it works fine. If I replace the toolx by a number I get:

Package pgfkeys Error: I do not know the key '/tikz/symbolic x coords' and I am going to ignore it. Perhaps you misspelled it.

4
  • what is the rest of the error? Which system? What is your pgfplots version? I get the correct result. – percusse Jun 20 '16 at 15:03
  • @percusse : I edited the question and included the answers to your questions. – Jonas Jun 20 '16 at 15:29
  • Yes, both your pgfplots and tikz versions are outdated. You need to update your packages. – percusse Jun 20 '16 at 16:50
  • thank you for your comments, I assumed that to be the problem. However I failed when I tried to update it, thats another question maybe.. For now the workaround I postet is sufficient for me – Jonas Jun 20 '16 at 17:11
0

As percusse pointed out the problem might be outdated versions of tikz and pgfplots.

However I got the result I wanted by a workaround:

file data.txt :

1, 99
2, 120
3, 80

tex code :

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
  \begin{figure}[h!]
    \centering
    \begin{tikzpicture}[scale=1]
      \begin{axis}[
        ybar,
        xtick=data,
        xmin=0.5,
        xmax=3.5,
        ymajorgrids=true,
        bar width=1cm, 
        xlabel={something else},
        xlabel style={yshift=-1cm},
        xtick align=inside,
        xticklabels={one bar, another bar , third bar},
        ylabel={something},
        x tick label style={font=\normalsize, rotate=45, anchor=east}
        ]
        \addplot table [x index=0,y index=1, col sep=comma] {data.txt};
      \end{axis}
    \end{tikzpicture}
    \caption[TODO]{TODO}
    \label{label}
  \end{figure}
\end{document}

result :

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.