Yesterday, I asked how to add numbers to the top of clustered bars in a bar graph with pgfplots in a MWE from the pgfplots manual, and got great answers. However, I've been unable to modify the solution to work for my graph; I get the error, "Missing number, treated as zero" right after width = 0.8\textwidth]. How can I fix this?
Code:
\documentclass{article}
\usepackage{pgfplots,pgfplotstable}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ymin=0,
symbolic x coords={float,small int,int,latin string,string,heterogeneous},
xtick=data]
ylabel=CPU Cycles,
legend style={at={(0.5,-0.15)},
anchor=north,legend columns=-1},
ybar=5pt,% configures `bar shift'
bar width=9pt,
width = 0.8\textwidth
]
\addplot[y1,fill=blue] coordinates {
(float,42)
(small int,50)
(int,80)
(latin string,80)
(string,40)
(heterogeneous,50)
};
\addplot[y2,fill=blue] coordinates {
(float,42)
(small int,50)
(int,80)
(latin string,80)
(string,40)
(heterogeneous,50)
};
\addplot [
only marks,
point meta=explicit,
nodes near coords={\pgfmathprintnumber[precision=1]{\pgfplotspointmeta}\%},
nodes near coords style={above}
]
table[
x=x,
y expr={max(\thisrow{y1},\thisrow{y2})},
% meta expr={(1-\thisrow{y2}/\thisrow{y1}) * 100}] {\mydata};
meta expr={100*(1-\thisrow{y1}/\thisrow{y2})}] {\mydata};
\legend{Far,Near}
\end{axis}
\end{tikzpicture}
\end{document}
The working version, which I'm trying to modify, is the following:
\documentclass{article}
\usepackage{pgfplots,pgfplotstable}
\pgfplotsset{compat=1.14}
\pgfplotstableread{
x y1 y2
1930 50e6 38e6
1940 33e6 42e6
1950 40e6 43e6
1960 50e6 45e6
1970 70e6 65e6
}\mydata
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ymin=0,
x tick label style={
/pgf/number format/1000 sep=},
ylabel=Population,
enlarge x limits=0.15,
legend style={at={(0.5,-0.15)},
anchor=north,legend columns=-1},
ybar=5pt,% configures `bar shift'
bar width=9pt,
]
\addplot table[x=x,y=y1] {\mydata};
\addplot table[x=x,y=y2] {\mydata};
\addplot [
only marks,
point meta=explicit,
nodes near coords={\pgfmathprintnumber[precision=1,showpos]{\pgfplotspointmeta}\%},
nodes near coords style={above}
]
table[
x=x,
y expr={max(\thisrow{y1},\thisrow{y2})},
meta expr={(\thisrow{y2}-\thisrow{y1})/\thisrow{y1} * 100}] {\mydata};
\legend{Far,Near}
\end{axis}
\end{tikzpicture}
\end{document}

y1andy2keys doesn't exist, and the final\addplotcannot work because you have no\mydatatable. – Torbjørn T. Feb 27 '17 at 20:34