# How to draw a graph from CSV with TeX?

I am a complete beginner with TeX, I would like to draw JMH benchmark graph using TeX. Since I have output results in CSV format. This is my actual code:

\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{siunitx}
\usepackage{graphicx}
\pgfplotsset{compat=1.5}
\title{Performance Report}
\date{}

\begin{document}

\maketitle

\begin{tikzpicture}
\begin{axis}[title=Getbytes performance,
xlabel = String length,
ylabel = Performance op/s,
]

only marks,
mark = *,
/pgfplots/error bars/.cd,
x dir = both,
y dir = both,
x explicit,
y explicit,
]
table [
x=Param: length,
y=Score,
]
{jmh-result-getbytes.csv};

\end{axis}
\end{tikzpicture}

\end{document}


My CSV file:

"Benchmark","Mode","Threads","Samples","Score","Score Error (99.9%)","Unit","Param: encoding","Param: length"
"test","thrpt",1,25.000000,24275.400025,695.792149,"ops/ms",ISO-8859-1,1
"test","thrpt",1,25.000000,23954.805784,545.186364,"ops/ms",ISO-8859-1,2
"test","thrpt",1,25.000000,23205.982297,573.971327,"ops/ms",ISO-8859-1,4
"test","thrpt",1,25.000000,24272.662601,937.668790,"ops/ms",ISO-8859-1,8
"test","thrpt",1,25.000000,24324.370910,1122.289177,"ops/ms",ISO-8859-1,16
"test","thrpt",1,25.000000,23960.521519,928.378626,"ops/ms",ISO-8859-1,32


For me the x is : Param: length and y is : score

But when I run make plot.pdf I get the following message error :

! Package pgfplots Error: Sorry, could not retrieve column 'Param:     length' from

• I have added this line \pgfplotstableread[col header=false] I still get an error, I am not sure what the problem used – Bionix1441 May 15 '15 at 14:09

The percent character in the column header "Score Error (99.9%)" makes trouble because it removes the rest of the line as comment. The following example works around it by ignoring this character.

Also the header entries are surrounded by quotes. Quoting seems unsupported by pgfplots. Therefore the example adds the quotes to the column title specification as part of the title. Also you have to pray, that the cells do not contain the comma. Otherwise pgfplots thinks a new column has started, even if the comma is inside quotes.

\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{siunitx}
\usepackage{graphicx}
\pgfplotsset{compat=1.5}
\title{Performance Report}
\date{}

\begin{document}

\maketitle

\begin{tikzpicture}
\begin{axis}[title=Getbytes performance,
xlabel = Performance op/s,
ylabel = String length,
]

only marks,
mark = *,
/pgfplots/error bars/.cd,
x dir = both,
y dir = both,
x explicit,
y explicit,
]
table [
col sep=comma,
ignore chars=\%,
x="Param: length",
y="Score",
]
{jmh-result-getbytes.csv};

\end{axis}
\end{tikzpicture}

\end{document}


• Serious question: why do you have that red tint on the background? :) – henry May 15 '15 at 15:26
• @henry To make clear, that this is an image, apart from the background, there are thin double lines above and below. The markup language here is quite limited, thus I am using the "blockquote" feature with > at the start of line. – Heiko Oberdiek May 15 '15 at 15:41
• Oh... I see. Interesting. :) – henry May 15 '15 at 16:02