1

I want to be able to display the sum of the values on top of the bars. Below is my code and under that, an illustrated image that displays the values I want to show. Can this be done?

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    ybar stacked,
    bar width=15pt,
    ymin=0,
    nodes near coords,
    %enlargelimits=0.15,
    legend style={at={(0.5,-0.15)},
      anchor=north,legend columns=-1},
    ylabel={Seconds (s)},
    symbolic x coords={t1, t2, t3, t4},
    xtick=data,
    x tick label style={rotate=41,anchor=east},
    ]
\addplot+[ybar] plot coordinates {(t1, 70) (t2, 94) (t3, 70) (t4, 70)};
\addplot+[ybar] plot coordinates {(t1, 43) (t2, 43) (t3, 61) (t4, 71)};
\legend{\strut d1,\strut  d2,\strut  d3}
\end{axis}
\end{tikzpicture}
\end{document}

https://i.imgur.com/qPaYiKD.jpg \n

Edit:

\pgfplotsset{compat=1.14}

makes it so that the values reside inside the bars. Without it, a sum of values are stacked on top of the bars. I do however want the sum at the top, then the value of each bar displayed inside of them, just as in the illustration.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.