# Plotting stdev error graph from external data file

I am trying to plot a tikz error (standard deviation) graph but i keep getting a parsing error:

! Package PGF Math Error: Could not parse input 'D1-1k' as a floating point number, sorry. The unreadable part was near 'D1-1k'..

I think it is expecting a numeric value in the first column but i need it to be a text. My goal is to have a 12 bars standard deviation error plot with text labels on the x-axis to be read from the first column of the data file. The data file contents are:

File,Mean,STDev
D1-1k,0.58,0.30
D1-10k,0.59,0.30
D1-100k,0.58,0.30
D1-1M,0.58,0.30
D1-10M,0.59,0.30
D1-100M,0.61,0.28
D2-1k,8.40,4.72
D2-10k,8.16,4.75
D2-100k,8.12,4.67
D2-1M,8.22,4.75
D2-10M,8.10,4.73
D2-100M,9.13,4.94


and my code is:

\documentclass[sigconf]{acmart}

\usepackage[utf8]{inputenc}
\usepackage{pdfpages}
\usepackage{pgfplotstable}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\begin{document}

\begin{tikzpicture}
\begin{axis}
\addplot [only marks, error bars/.cd, y dir=both, y explicit]
table [col sep=comma, x=File, y=Mean, y error=STDev]{Data/detavg.csv};
\end{axis}
\end{tikzpicture}

\end{document}


Thank you.

One thing that does work is to add the required symbolic coordinates by hand.

\documentclass[sigconf]{acmart}
\usepackage{filecontents}
\begin{filecontents*}{detavg.csv}
File,Mean,STDev
D1-1k,0.58,0.30
D1-10k,0.59,0.30
D1-100k,0.58,0.30
D1-1M,0.58,0.30
D1-10M,0.59,0.30
D1-100M,0.61,0.28
D2-1k,8.40,4.72
D2-10k,8.16,4.75
D2-100k,8.12,4.67
D2-1M,8.22,4.75
D2-10M,8.10,4.73
D2-100M,9.13,4.94
\end{filecontents*}
\usepackage[utf8]{inputenc}
\usepackage{pdfpages}
\usepackage{pgfplotstable}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\begin{document}

\begin{tikzpicture}
\begin{axis}[width=0.8\textwidth,symbolic x coords={D1-1k,D1-10k,D1-100k,D1-1M,D1-10M,D1-100M,%
D2-1k,D2-10k,D2-100k,D2-1M,D2-10M,D2-100M},
x tick label style={rotate=45,anchor=east}]
\addplot [only marks, error bars/.cd, y dir=both, y explicit]
table [col sep=comma, x=File, y=Mean, y error=STDev]{detavg.csv};
\end{axis}
\end{tikzpicture}
\end{document}


Can this be made more automatic? It certainly can. (I would assume that something of that sort already exists but could not find it in the manual nor elsewhere.) Here is a version that extracts the coordinates from the file via a command \ListOfColumnEntries that was written for that purpose.

\documentclass[sigconf]{acmart}
\usepackage{filecontents}
\begin{filecontents*}{detavg.csv}
File,Mean,STDev
D1-1k,0.58,0.30
D1-10k,0.59,0.30
D1-100k,0.58,0.30
D1-1M,0.58,0.30
D1-10M,0.59,0.30
D1-100M,0.61,0.28
D2-1k,8.40,4.72
D2-10k,8.16,4.75
D2-100k,8.12,4.67
D2-1M,8.22,4.75
D2-10M,8.10,4.73
D2-100M,9.13,4.94
\end{filecontents*}
\usepackage[utf8]{inputenc}
\usepackage{pdfpages}
\usepackage{pgfplotstable}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\newcounter{mycol}
\begin{document}
\newcommand{\ListOfColumnEntries}[4][]{\setcounter{mycol}{0}
\ifnum\number\value{mycol}=0
\xdef#4{\cell}%
\else
\xdef#4{#4,\cell}%
\fi
\stepcounter{mycol}}}

\ListOfColumnEntries[col sep=comma]{detavg.csv}{File}{\LstSymbolicCoords}

\begin{tikzpicture}
\begin{axis}[width=0.8\textwidth,symbolic x coords/.expanded=\LstSymbolicCoords,
x tick label style={rotate=45,anchor=east}]
\addplot [only marks, error bars/.cd, y dir=both, y explicit]
table [col sep=comma, x=File, y=Mean, y error=STDev]{detavg.csv};
\end{axis}
\end{tikzpicture}

\end{document}


The output is as above.

• Thank you. It worked. – MoeS Sep 14 at 17:44