误差线上方的标签

误差线上方的标签

有人能帮我把这些标签放在误差线上方吗?除了标签之外,还有其他选项可以显示 SD 吗?

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots} 
\pgfplotsset{compat=1.18}
\begin{document}

\usetikzlibrary{patterns}
\begin{tikzpicture}

\begin{axis}[
    ybar, axis on top,
    height=11cm, width=14.5cm,
    bar width=0.4cm,
    ybar=3pt,
    enlarge y limits={value=.1,upper},
    ymin=25, ymax=400,
    axis x line*=bottom,
    axis y line*=left,
    y axis line style={opacity=0},
    tickwidth=1pt,
    enlarge x limits=true,
     ymajorgrids=true,
major grid style={lines,lightgray},
    legend style={
        at={(0.5,-0.1)},
        anchor=north,
        legend columns=5,
        /tikz/every even column/.append style={column sep=0.5cm}},
    ylabel=\textbf{Weekly accumulated load (\% of match)},
    symbolic x coords={TD (m),HSR (m),SPR (m),Acc. (\#),Dec. (\#)},
xtick=data, 
ticklabel style={/pgf/number format/.cd, use comma, 1000 sep = {}},
    nodes near coords,
nodes near coords align={vertical},
nodes near coords={\pgfkeys{/pgf/fpu}\pgfmathparse{\pgfplotspointmeta}\pgfmathprintnumber{\pgfmathresult}\,\%},
 every node near coord/.append style={font=\scriptsize, rotate=0, yshift=20},
every axis legend/.append style={font=\scriptsize}],
    \addplot[draw=none, postaction={pattern=north east lines}, fill=white, error bars/.cd,y dir=both,y explicit,error bar style={line width=0.1pt}]
        coordinates 
        {
        (TD (m), 225) +- (TD (m),24)
        (HSR (m),142) +- (HSR (m),31)
        (SPR (m), 235) +- (SPR (m),54)
        (Acc. (\#), 279) +- (Acc. (\#),38)
        (Dec. (\#), 225) +- (Dec. (\#),56)
        };
    \addplot[draw=none, postaction={pattern=dots},fill=gray, pattern color= black,error bars/.cd,y dir=both,y explicit,error bar style={line width=0.1pt}]
         coordinates {
         (TD (m), 190) +- (TD (m),18)
         (HSR (m),88) +- (HSR (m),20) 
         (SPR (m), 112) +- (SPR (m),28) 
         (Acc. (\#), 247) +- (Acc. (\#),40) 
         (Dec. (\#), 188) +- (Dec. (\#),33)
         };
    \addplot[draw=none, fill=black, error bars/.cd,y dir=both,y explicit,error bar style={line width=0.1pt}]
         coordinates {
         (TD (m), 190) +- (TD (m),11) 
         (HSR (m),123) +- (HSR (m),21) 
         (SPR (m), 169) +- (SPR (m),39)  
         (Acc. (\#), 212) +- (Acc. (\#),29) 
         (Dec. (\#), 158) +- (Dec. (\#),30)
         };
    \addplot[draw=none, fill=lightgray, error bars/.cd,y dir=both,y explicit, error bar style={line width=0.1pt}]
         coordinates {
         (TD (m), 199) +- (TD (m),17) 
         (HSR (m),103) +- (HSR (m),21) 
         (SPR (m), 116) +- (SPR (m),25) 
         (Acc. (\#), 253) +- (Acc. (\#),30) 
         (Dec. (\#), 169) +- (Dec. (\#),18)
         };
        \legend{CB, WB, CM, CF}
\end{axis}

\end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

这是一个基于的解决方案https://tex.stackexchange.com/a/130318/263192https://tex.stackexchange.com/a/200575/263192

我已将您的数据移至pgfplotstable表格中,以便可以在中引用数据visualization depends on

不幸的是,这只在 之前有效compat=1.10

\documentclass[border=10]{standalone}
\usepackage{pgfplots} 
\pgfplotsset{compat=1.10}
\usepackage{pgfplotstable} 

\pgfplotstableread[col sep=comma]{
X, Y, E
TD (m), 225, 24
HSR (m),142, 31
SPR (m), 235, 54
Acc. (\#), 279, 38
Dec. (\#), 225, 56
}\tA

\pgfplotstableread[col sep=comma]{
X, Y, E
TD (m), 190, 18
HSR (m),88, 20
SPR (m), 112, 28
Acc. (\#), 247, 40
Dec. (\#), 188, 33
}\tB

\pgfplotstableread[col sep=comma]{
X, Y, E
TD (m), 190, 11
HSR (m),123, 21
SPR (m), 169, 39
Acc. (\#), 212, 29
Dec. (\#), 158, 30
}\tC

\pgfplotstableread[col sep=comma]{
X, Y, E
TD (m), 199, 17
HSR (m),103, 21
SPR (m), 116, 25
Acc. (\#), 253, 30
Dec. (\#), 169, 18
}\tD

\begin{document}
\usetikzlibrary{patterns}
\begin{tikzpicture}

\begin{axis}[
    ybar, axis on top,
    height=11cm, width=19cm,
    bar width=0.6cm,
    ybar=3pt,
    enlarge y limits={value=.1,upper},
    ymin=25, ymax=400,
    axis x line*=bottom,
    axis y line*=left,
    y axis line style={opacity=0},
    tickwidth=1pt,
    enlarge x limits=true,
    ymajorgrids=true,
    major grid style={lightgray},
    legend style={
        at={(0.5,-0.1)},
        anchor=north,
        legend columns=5,
        /tikz/every even column/.append style={column sep=0.5cm}},
    ylabel=\textbf{Weekly accumulated load (\% of match)},
    symbolic x coords={TD (m),HSR (m),SPR (m),Acc. (\#),Dec. (\#)},
    xtick=data, 
    ticklabel style={/pgf/number format/.cd, use comma, 1000 sep = {}},
    nodes near coords,
    nodes near coords align={vertical},
    nodes near coords={\pgfkeys{/pgf/fpu}\pgfmathparse{\pgfplotspointmeta}\pgfmathprintnumber{\pgfmathresult}\,\%},
    visualization depends on=\thisrow{E} \as \sd,
    every node near coord/.append style={
        font=\scriptsize,
        rotate=0,
        shift={(0,transformdirectiony(\sd))}
    },
    every axis legend/.append style={font=\scriptsize}
]
    \addplot[draw=none, postaction={pattern=north east lines}, fill=white, error bars/.cd,y dir=both,y explicit,error bar style={line width=0.1pt}]
        table[x=X,y=Y,y error=E] {\tA};
    \addplot[draw=none, postaction={pattern=dots},fill=gray, pattern color= black,error bars/.cd,y dir=both,y explicit,error bar style={line width=0.1pt}]
        table[x=X,y=Y,y error=E] {\tB};
    \addplot[draw=none, fill=black, error bars/.cd,y dir=both,y explicit,error bar style={line width=0.1pt}]
        table[x=X,y=Y,y error=E] {\tC};
    \addplot[draw=none, fill=lightgray, error bars/.cd,y dir=both,y explicit, error bar style={line width=0.1pt}]
        table[x=X,y=Y,y error=E] {\tD};
    \legend{CB, WB, CM, CF}
\end{axis}

\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容