I'm trying to create groups of 5 stacked xbars, using y expr={\thisrow{y} - (mod(\thisrow{y},5)/2)}. However, after some groups, the calculation seems to get thrown off and the third group actually consists of 6 bars:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}
\usepackage{pgfplotstable}
\begin{document}
\pgfplotstableread{%
x y
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
11 11
12 12
13 13
14 14
15 15
16 16
17 17
18 18
19 19
20 20
21 21
}\loadedtable
\begin{figure}[h]
\begin{tikzpicture}
\begin{axis}[xbar stacked, ytick=data, y=0.9cm]
\addplot table[x=x,y expr={\thisrow{y} - (mod(\thisrow{y},5)/2)}] \loadedtable ;
\addplot table[x=x,y expr={\thisrow{y} - (mod(\thisrow{y},5)/2)}] \loadedtable ;
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}


Modis not in there yet andmoduses truncation – percusse Nov 19 '13 at 22:26\thisrow, not withmod. Try\pgfmathsetmacro\myresult{15-0.5*mod(15,5)} \draw node {\myresult};inside atikzpictureand you get 15, as expected. – jub0bs Nov 19 '13 at 23:15\foreach[count=\xi] \x in {15,30,40,55} { \pgfmathsetmacro\myresult{\x-0.5*mod(\x,5)} \draw (\xi,0) node {\myresult}; }produces fine results. – jub0bs Nov 19 '13 at 23:39