You need to add the ybar
option to the axis
options, instead of to each plot individually. Note that the author of pgfplots
recommends not to use the newest
compat
option, and also I think that loading the pgfplotslibrary
units
is redundant if you also load siunitx
. Finally, pgfplots
already loads tikz
so no need for duplication there either :-)
\documentclass{article}
\usepackage{siunitx}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\sisetup{
round-mode = places,
round-precision = 2,
}
\begin{document}
\begin{figure}[h!]
\begin{center}
\begin{tikzpicture}
\begin{axis}[
width=15cm, height=8cm,
grid=major,
grid style={dashed,gray!30},
xlabel=String length,
ylabel=Performance ops/ms,
legend style={at={(0.5,-0.2)},anchor=north},
xmode=log,
log ticks with fixed point,
xtick=data,
ybar, %added here
]
\addplot[fill] table[x="length",y="Score", col sep=comma] {jmh-result1.csv};
\addplot[green,fill] table[x="length",y="Score", col sep=comma] {jmh-result2.csv};
\end{axis}
\end{tikzpicture}
\caption{Performance Comparison Histogram}
\end{center}
\end{figure}
\end{document}
You can use it as follows: Don't use macro names starting with \the
. That is a special case for TeX and might lead to mistakes that are very difficult to debug.
\documentclass{article}
\usepackage{pgfplotstable}
\begin{document}
\begin{tikzpicture}
\pgfplotstableread[col sep=comma,header=false]{
12.3458,0.709423,0.018174,10.3177,0.031258,0.360285,0.071809,0
13.3458,0.709423,0.018174,10.3177,0.031258,0.360285,0.171809,0
7.88918,0.037782,0.010597,13.0123,0.027078,0.345659,0.070872,1
8.88918,0.037782,0.010597,13.0123,0.027078,0.345659,0.170872,1
3.29679,0.175776,0.012142,18.2475,0.031448,0.292123,0.141521,2
4.29679,0.175776,0.012142,18.2475,0.031448,0.292123,0.241521,2
3.94161,0.204657,0.002334,2.09774,0.011567,0.278266,0.113811,3
4.94161,0.204657,0.002334,2.09774,0.011567,0.278266,0.213811,3
}\mydata
\begin{axis}[width=7cm,height=7cm]
\addplot+[scatter, only marks,
scatter/classes={0={mark=square*,green},
1={mark=triangle*,black},
2={mark=o,blue},
3={mark=x,red}
},
scatter src=explicit symbolic
] table[x index=0,y index=6,meta index=7] \mydata;
\end{axis}
\end{tikzpicture}
\end{document}
Best Answer
PGFPlots can calculate histograms. By using three
axis
environments positioned relative to each other, you can get the desired output:random.dat
: