0

I am new to LaTeX. How can I draw a graph for this data...

files   1  5.350    ±0.011 ns/op
files 250  218.984  ±0.290 ns/op
files 500  545.244  ±3.784 ns/op
files 750  822.573  ±6.720 ns/op
files 1000 1192.118 ±2.157 ns/op

scanner   1  5.290 ±0.010 ns/op
scanner 250  263.696 ±0.818 ns/op
scanner 500  595.838 ±1.886 ns/op
scanner 750  961.677 ±2.784 ns/op
scanner 1000 1387.766 ±113.272 ns/op

So I want both files and scanner to be on the same graph and for both the error ranges show up as well. y-axis would be time taken. x-axis would be 1, 250, 500, 750, 1000. So basically the graph has two lines - one for scanner, one for files. And each plot should be a dot and also show error range in the same graph like Plotting standard error. I would also like with a line graph for a bar chart like pgfplots: Bar graph with confidence intervals (error)

1 Answer 1

0

Welcome! This is to give you a start. I had to remove the ± signs from the data. The errors seem to be overall very tiny.

\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\pgfplotstableread[header=false]{
files   1  5.350    0.011 ns/op
files 250  218.984  0.290 ns/op
files 500  545.244  3.784 ns/op
files 750  822.573  6.720 ns/op
files 1000 1192.118 2.157 ns/op
}\datasetA
\pgfplotstableread[header=false]{
scanner 1 avgt 10 5.290 0.010 ns/op
scanner 250 avgt 10 263.696 0.818 ns/op
scanner 500 avgt 10 595.838 1.886 ns/op
scanner 750 avgt 10 961.677 2.784 ns/op
scanner 1000 avgt 10 1387.766 113.272 ns/op
}\datasetB

\begin{tikzpicture}
\begin{axis}[ylabel={data},xtick=data,
    legend style={at={(0.05,0.95)},anchor=north west}]
\addplot[color=blue,error bars/.cd,y dir=both,y explicit] 
    table[x index=1,y index=2,y error index=3] 
    \datasetA; %
\addlegendentry{files}  
\addplot[color=red,error bars/.cd,y dir=both,y explicit] 
    table[x index=1,y index=4,y error index=5] 
    \datasetB; %
\addlegendentry{scanner}        
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

2
  • 2
    @levivah940 A % indicates a comment, i.e. everything after % in a given line won't be "compiled". Very often it is also used to suppress spurious spaces. In the above code, it is unimportant. I was considering adding some comment but then let it be but did not remove the %. However, the % does certainly not hurt here either.
    – user194703
    Mar 13, 2020 at 23:07
  • 2
    @levivah940 In order to make these bar charts, just add ybar,, e.g. after xtick=data,. You can then also specify fill colors, e.g. \addplot[color=blue,fill=blue!60,error bars/.cd,y dir=both,y explicit] table[x index=1,y index=2,y error index=3] \datasetA;.
    – user194703
    Mar 13, 2020 at 23:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy