![前景中的 pgfplot 错误栏](https://linux22.com/image/300444/%E5%89%8D%E6%99%AF%E4%B8%AD%E7%9A%84%20pgfplot%20%E9%94%99%E8%AF%AF%E6%A0%8F.png)
我想将下方 y 轴的误差线置于堆叠轴的顶部。我可以使用哪个命令将误差线置于最前面?提前谢谢您。
\documentclass[a4paper,twoside,11pt]{scrreprt}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usetikzlibrary{positioning}
\usetikzlibrary{decorations.pathmorphing}
\pgfplotsset{compat=newest}
\usetikzlibrary{arrows}
\usetikzlibrary{patterns}
\usepackage{filecontents}
\begin{document}
\begin{filecontents}{A3Met.dat}
X Y Z Y_error Z_error Y_label Z_label
{ctr.} 0.26 0.407 0.1 0.1 0.39 0.61
{Probe} 0.3778 0.314 0.1 0.1 0.55 0.45
\end{filecontents}
\begin{tikzpicture}
\begin{axis}[
bar width=1cm,
x=2cm,
y=4cm,
ytick={0,0.2,0.4,...,1},
enlarge x limits={abs=1cm},
symbolic x coords={{ctr.},{Probe},},
ymin=0,
ymax=1.05,
ylabel={Aufnahme in rel. Einheiten},
xticklabel style={text width=2cm, align=center},
xtick=data,
axis x line*=bottom,
axis y line=left,
yticklabel={\pgfmathparse{\tick*100}\pgfmathprintnumber{\pgfmathresult}\%} ,
nodes near coords,
visualization depends on=abs(y)/y*(0.15+\thisrow{Y_error}) \as \myshift,
every node near coord/.append style={yshift=-transformdirectiony(\myshift),inner sep=1pt},
legend style={at={(1.8,0.5)},anchor=east, legend cell align=left,
reverse legend},
]
\addplot +[
ybar stacked,
color=black,
fill=gray!50,
mark=none,
point meta=explicit symbolic,
every node near coord/.append style={anchor=south},
error bars/.cd,
y dir=both,
y explicit,
] table
[y=Y, x=X, y error=Y_error, meta=Y_label] {A3Met.dat};
\addlegendentry{Ph}
\addplot +[
ybar stacked,
color=black,
fill=white,
mark=none,
point meta=explicit symbolic,
every node near coord/.append style={anchor=south},
error bars/.cd,
y dir=both,
y explicit
] table [y=Z, x=X, y error=Z_error, meta=Z_label]{A3Met.dat};
\addlegendentry{Tr}
\end{axis}
\end{tikzpicture}
\end{document}
答案1
对于fill=white
第二个图,请使用fill opacity=0,text opacity=1
。这仅适用于白页,但我想大多数情况都是如此。
\documentclass[a4paper,twoside,11pt]{scrreprt}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usetikzlibrary{positioning}
\usetikzlibrary{decorations.pathmorphing}
\pgfplotsset{compat=newest}
\usetikzlibrary{arrows}
\usetikzlibrary{patterns}
\usepackage{filecontents}
\begin{document}
\begin{filecontents}{A3Met.dat}
X Y Z Y_error Z_error Y_label Z_label
{ctr.} 0.26 0.407 0.1 0.1 0.39 0.61
{Probe} 0.3778 0.314 0.1 0.1 0.55 0.45
\end{filecontents}
\begin{tikzpicture}
\begin{axis}[
bar width=1cm,
x=2cm,
y=4cm,
ytick={0,0.2,0.4,...,1},
enlarge x limits={abs=1cm},
symbolic x coords={{ctr.},{Probe},},
ymin=0,
ymax=1.05,
ylabel={Aufnahme in rel. Einheiten},
xticklabel style={text width=2cm, align=center},
xtick=data,
axis x line*=bottom,
axis y line=left,
yticklabel={\pgfmathparse{\tick*100}\pgfmathprintnumber{\pgfmathresult}\%} ,
nodes near coords,
visualization depends on=abs(y)/y*(0.15+\thisrow{Y_error}) \as \myshift,
every node near coord/.append style={yshift=-transformdirectiony(\myshift),inner sep=1pt},
legend style={at={(1.8,0.5)},anchor=east, legend cell align=left,
reverse legend},
]
\addplot +[
ybar stacked,
color=black,
fill=gray!50,
mark=none,
point meta=explicit symbolic,
every node near coord/.append style={anchor=south},
error bars/.cd,
y dir=both,
y explicit,
] table
[y=Y, x=X, y error=Y_error, meta=Y_label] {A3Met.dat};
\addlegendentry{Ph}
\addplot +[
ybar stacked,
color=black,
fill opacity=0,text opacity=1,
mark=none,
point meta=explicit symbolic,
every node near coord/.append style={anchor=south},
error bars/.cd,
y dir=both,
y explicit
] table [y=Z, x=X, y error=Z_error, meta=Z_label]{A3Met.dat};
\addlegendentry{Tr}
\end{axis}
\end{tikzpicture}
\end{document}