I and trying to use foreach loop and pgfmathparse inside axis. But it is giving me an error.
\documentclass[10pt,border=0pt]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{siunitx}
% Default options for plots
\pgfplotsset{%
compat=1.12,
compat/show suggested version=false,
%tick label style={font=\footnotesize},
%label style={font=\footnotesize},
legend style={%
%draw=none,
font=\footnotesize,
at={(0.5,1.0)}, % position of legend
yshift=3pt,
anchor=south,
legend columns=2
legend cell align=left,
inner xsep=2pt,
/tikz/column 2/.style={%
column sep=4pt, % http://tex.stackexchange.com/questions/80215/two-columns-in-legend-in-pgfplots
},
/tikz/column 1/.style={%
column sep=2pt,
},
/tikz/column 3/.style={%
column sep=2pt,
},
nodes={inner xsep=0pt,inner ysep=0pt,text depth=0.15em},
%nodes={inner xsep=2pt,inner ysep=0pt,text depth=0.15em}, % this added a space after the last text
},
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
width=20cm,
ybar stacked,
bar width=1cm,
ylabel={YLABEL},
symbolic x coords={a,b,c,d,e,f},
ticks=none,
%xtick={a,b,c,d,e,f}, % adds legend at ticks
%enlarge x limits=0.5,
%enlarge x limits,
enlarge y limits=0.2,
nodes near coords,
font=\footnotesize,
grid=major,
after end axis/.code={% http://tex.stackexchange.com/questions/55261/labeling-the-axes-of-my-plot
\node[below] at (xticklabel cs:0.25) {XXX};
\node[below] at (xticklabel cs:0.75) {YYY};
}
]
\addplot coordinates {(a,5.42) (b,13.4) (c,10.69) (d,10.81) (e,30.31) (f,22.53)};
\addplot coordinates {(a,0.72) (b,17.87) (c,5) (d,1.40) (e,12.39) (f,5.17)};
\legend {Downlink,Uplink};
\foreach \x/\y in {1/a,2/b,3/c,4/a,5/b,6/c)} {%
\pgfmathsetmacro{\coor}{\x*(0.5/6)}
\node[draw,anchor=south west] at (rel axis cs:\coor,0.8) {\y};
};
\end{axis}
\end{tikzpicture}
\end{document}