8

The picture below is almost what I need and is generated by the MWE below. All I require is to include percentage symbols on the labels on the nodes. So they should read: 34%, 22% and 13%.

enter image description here

----------- MWE ---------------------

\documentclass{article}

\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    symbolic x coords={A,B,C},
    nodes near coords,
    xtick=data
    ]
    \addplot[ybar,fill=blue] coordinates {
        (A,34)
        (B,22)
        (C,13)
    };
\end{axis}
\end{tikzpicture}

\end{document}
8

By default nodes near coords prints \pgfmathprintnumber{\pgfplotspointmeta}. You can add a percent sign by saying

nodes near coords=\pgfmathprintnumber{\pgfplotspointmeta}\%

output of code

\documentclass{article}

\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    symbolic x coords={A,B,C},
    nodes near coords=\pgfmathprintnumber{\pgfplotspointmeta}\%,
    xtick=data
    ]
    \addplot[ybar,fill=blue] coordinates {
        (A,34)
        (B,22)
        (C,13)
    };
\end{axis}
\end{tikzpicture}

\end{document}
  • Very useful! This will go into my collection. – Dr. Manuel Kuehner May 20 '17 at 17:10
4

\documentclass{article}

\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
% https://tex.stackexchange.com/questions/350129
\begin{axis}[
    symbolic x coords={A,B,C},
    nodes near coords,
    point meta=explicit symbolic,
    xtick=data,
    ]
    \addplot[ybar,fill=blue] coordinates {
        (A,34) [34 \%]
        (B,22) [22 \%]
        (C,13) [13 \%]
    };
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.