안녕하세요. 저는 수량이 2개뿐인 막대 그래프를 가지고 있는데 각 수량이 동일한 오류 막대를 가지도록 만들고 싶습니다(예: 모든 빨간색 막대에는 오류 A가 있고 모든 주황색 막대에는 오류 B가 있음). 감사합니다
\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.3}
\definecolor{mygray}{HTML}{c7c7c7}
\definecolor{myblue}{HTML}{4385f5}
\definecolor{myred}{HTML}{ea4136}
\definecolor{myorange}{HTML}{fcbc05}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar=0pt,
enlarge x limits=0.06,
% (merged both styles)
legend style={
at={(0.5,-0.15)},
anchor=north,
legend columns=-1,
draw=none,
/tikz/every even column/.append style={column sep=0.3cm},
},
height=6cm,
width=10cm,
ymajorgrids,
tick align=inside,
ymin=0,
ymax=20,
ytick distance=2,
ylabel={Amplitud (grados)},
y axis line style={opacity=0},
tickwidth=0pt,
ylabel={Amplitud (grados)},
symbolic x coords={medida 1, medida 2, medida 3, medida 4, medida 5, medida 6},
xtick=data,
nodes near coords,
every node near coord/.append style={font=\tiny},
bar width=13pt,
cycle list={
{fill=myred,draw=black},
{fill=myorange,draw=black},
{fill=myblue,draw=black},
{fill=myorange,draw=black}%
},
error bars/y dir=both,
error bars/y fixed=2,
]
\addplot coordinates {(medida 1,10) (medida 2,11) (medida 3,12) (medida 4,13) (medida 5, 14) (medida 6, 15)};
\addplot coordinates {(medida 1,7) (medida 2,8) (medida 3,8) (medida 4,8) (medida 5, 9) (medida 6, 9)};
\legend{Amplitud inicial $\theta_i$, Amplitud final $\theta_f$ }
\end{axis}
\end{tikzpicture}
\end{document}
답변1
전역 옵션을 로컬 위치에 두십시오.
\addplot[error bars/y fixed=4, fill=red]
힌트 1: 나는 개별 점이나 이와 유사한 것을 추가하는 데에만 좌표 플롯을 사용합니다. 좌표 플롯은 더 복잡한 입력 데이터에는 적합하지 않습니다. 그래서 나는 그것으로 테이블 플롯을 만들었습니다.
힌트 2:nodes near coords
좀 더 눈에 띄는 곳으로 옮겼습니다 .
\documentclass[border=10pt]{standalone}
\usepackage{pgfplotstable}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pgfplotstableread[]{
X Y1 Y2
1 10 7
2 11 8
3 12 8
4 13 8
5 14 9
6 15 9
}\mytable
\definecolor{mygray}{HTML}{c7c7c7}
\definecolor{myblue}{HTML}{4385f5}
\definecolor{myred}{HTML}{ea4136}
\definecolor{myorange}{HTML}{fcbc05}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
height=6cm,
width=10cm,
ybar=0pt,
bar width=13pt,
enlarge x limits=0.075, %<--- !
% (merged both styles)
legend style={
at={(0.5,-0.15)},
anchor=north,
legend columns=-1,
draw=none,
/tikz/every even column/.append style={column sep=0.3cm},
},
ymajorgrids,
tick align=inside,
ymin=0,
ymax=20,
ytick distance=2,
ylabel={Amplitud (grados)},
y axis line style={opacity=0},
tickwidth=0pt,
xticklabel={media \pgfmathprintnumber{\tick}}, % <---- !
xtick=data,
nodes near coords,clip=false,
every node near coord/.append style={font=\tiny},
% Suggestion ================
visualization depends on = y \as \Yshift,
node near coord style = {
shift = { (axis direction cs: 0, -0.75*\Yshift) }
},
% ================
% error bars/.cd, % <--- could be useful
error bars/y dir=both,
% error bars/y fixed=2, %<-- putted to addplot
]
\addplot[error bars/y fixed=4,
fill=myred,] table[x=X, y=Y1]{\mytable};
\addplot[error bars/y fixed=0.666,
fill=myorange] table[x=X, y=Y2]{\mytable};
\legend{Amplitud inicial $\theta_i$, Amplitud final $\theta_f$ }
\end{axis}
\end{tikzpicture}
\end{document}
% Not needed:
%cycle list={
%{fill=myred,draw=black},
% {fill=myorange,draw=black},
% {fill=myblue,draw=black},
% {fill=myorange,draw=black}%
%},
% Not needed in table plot:
%symbolic x coords={medida 1, medida 2, medida 3, medida 4, medida 5, medida 6},
%\addplot[error bars/y fixed=4, fill=myred] coordinates {(medida 1,10) (medida 2,11) (medida 3,12) (medida 4,13) (medida 5, 14) (medida 6, 15)};
%\addplot[error bars/y fixed=1, fill=myorange] coordinates {(medida 1,7) (medida 2,8) (medida 3,8) (medida 4,8) (medida 5, 9) (medida 6, 9)};