Reputation: 53
I'm trying to use data from a .csv file to create a barchart with labels that are non-numeric. I've looked through a few older examples, but they seem large and clunky. I'm hoping there's a better way. Here's what I have so far as a MWE:
\documentclass[11pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xlabel=x axis label,ylabel=y axis label]
\addplot [ybar] table [symbolic x coords=Month, y=Dozers, col sep=comma] {cnrldata.csv};
\end{axis}
\end{tikzpicture} \\
\end{document}
From this I of course get the error:
Package PGF Math Error: Could not parse input 'May 14' as a floating point number, sorry. The unreadable part was near 'May 14'.. ... y=Dozers, col sep=comma] {data.csv};
The data in the table looks like this:
Month, Dozers,
January, 0.85,
February, 0.7,
Upvotes: 0
Views: 4442
Reputation: 10939
Your usage of symbolic x coords
is wrong. Read the manual.
Tip: You are more likely to get such questions answered on TeX.SX.
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel={$x$ axis label},
ylabel={$y$ axis label},
symbolic x coords={January,February,March,April,May},
]
\addplot [ybar] table [x=Month, y=Dozers, col sep=comma] {
Month, Dozers
January, 0.85
February, 0.7
March, 0.6
April, 0.9
May, 0.4
};
\end{axis}
\end{tikzpicture}
\end{document}
Upvotes: 1