Based on this question I was able to put partial and total values on my bar plot. My bars have some really small values though and it is impossible to fit the numbers in some ranges. I would like to shift those label on the side. How can I do?
Note that in one case I have two consecutive small ranges, so it would be awesome have those values on alternate sides.
Thanks in advance!
Here is what I have so far:
And the related code:
\documentclass[tikz,border=10pt]{standalone}
\usepackage{pgfplots,pgfplotstable}
\pgfplotsset{compat=1.9}
\begin{document}
\begin{tikzpicture}
\pgfplotsset{
show sum on top/.style={
/pgfplots/scatter/@post marker code/.append code={%
\node[
at={(normalized axis cs:%
\pgfkeysvalueof{/data point/x},%
\pgfkeysvalueof{/data point/y})%
},
anchor=south,
]
{\pgfmathprintnumber{\pgfkeysvalueof{/data point/y}}};
},
},
}
\begin{axis}[ybar stacked,
nodes near coords,
title={Energy spent},
xtick={0,...,4},
bar width=25pt,
ymin=0,
enlarge x limits=0.125,
ylabel = Energy (J),
legend entries={A,
B,
C,
D},
legend pos=outer north east,
]
\addplot[fill=blue!80] coordinates
{(0,0) (1,0) (2,20.544) (3,21.192)};
\addplot[fill=cyan!80] coordinates
{(0,0) (1,0) (2,9.610) (3,9.681)};
\addplot[fill=red!80] coordinates
{(0,0.505) (1,12.505) (2,0.247) (3,1.975)};
\addplot[fill=pink!80, show sum on top] coordinates
{(0,3.772) (1,1.075) (2,0.439) (3,2.066)};
\end{axis}
\end{tikzpicture}
\end{document}

