1

How can I show values of error on top of error bar? In the figure, I want to add values which are written with pencil in black.

MWE:

\documentclass{standalone}

\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{pgfplotstable}
\usepackage{filecontents}

\begin{document}

    \begin{filecontents*}{data.txt}
        np slow diff
        16 1.40973 0.93363
        64 0.26585 1.72152
        128 0.115072 0.636881
    \end{filecontents*}

    \begin{tikzpicture}
        \begin{axis}[
            xtick={0,1,2},
            ybar,
            ymin=0,
            enlarge x limits=0.2,
            ]
            \addplot+ [draw=black,error bars/.cd, y dir=plus, y explicit,error bar style={line width=1pt},error mark options={black,line width=1pt,mark size=3pt,rotate=90}] table [y=slow, x expr=\coordindex, y error=diff] {data.txt};
        \end{axis}
    \end{tikzpicture}

\end{document}

enter image description here

4

This can be done using the nodes near coords feature of PGFPlots. By default they would be shown above the bars and show the values of the bars, but with some minor modifications these nodes can be shifted and show the error bar values. I guess the code is self-explanatory. If not, please let me know and I will add some comments to the code.

% used PGFPlots v1.16
    \begin{filecontents*}{data.txt}
        np slow diff
        16 1.40973 0.93363
        64 0.26585 1.72152
        128 0.115072 0.636881
    \end{filecontents*}
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        xtick={0,1,2},
        ybar,
        ymin=0,
        enlarge x limits=0.2,
        visualization depends on={\thisrow{diff} \as \myvalue},
        node near coords style={
            shift={(axis direction cs:0,\myvalue)}
        },
        nodes near coords={\pgfmathprintnumber{\myvalue}},
    ]
        \addplot+ [
            draw=black,
            error bars/.cd,
                y dir=plus,
                y explicit,
                error bar style={
                    line width=1pt,
                },
                error mark options={
                    black,
                    line width=1pt,
                    mark size=3pt,
                    rotate=90,
                },
            ] table [y=slow, x expr=\coordindex, y error=diff] {data.txt};
    \end{axis}
\end{tikzpicture}
\end{document}

image showing the result of above code

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.