[Tex/LaTex] Plotting error Bars in PGF plots

pgfplots

I want to plot error bars in PGFplots using the following Latex code but its not showing any error neither the error bars.

I know I should mention the error values explicitly but what if i do not want to calculate errors (standard deviation) of every point manually.

Any help regarding this would be highly appreciated. Thanks.

\documentclass[conference]{IEEEtran}
\ifCLASSINFOpdf
\else
\fi
\hyphenation{op-tical net-works semi-conduc-tor}
\usepackage[pdftex]{graphics}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepgfplotslibrary{dateplot}
\usepgfplotslibrary{patchplots}
\pgfplotsset{compat=1.7}



\pgfplotsset{footnotesize,samples=10}
\begin{figure}[t]
\centering
\begin{tikzpicture}
\begin{axis}[ % The height and width argument only apply to the actual axis
title style={at={(0.3,0.2)},anchor=north,yshift=-0.1},
title =\textbf{Correlation= 0.672658953},
height=5cm,
width=8cm,
legend style={at={(0.5,1.3)},anchor=north},
ylabel={PDR},
xlabel={LQI},
xmin=85, xmax=120,
ymin=80, ymax=100,
xtick= {85,90,95,100,105,110,115,120},
ytick= {80,85,90,95,100},
legend columns=4,
ymajorgrids=true,
grid style=dashed,
]
\addplot[
mark=o,
mark size=1.4pt,
only marks,
]
plot [error bars/.cd, y dir = both, y explicit]
coordinates {
(104,   97)(98  ,97)(105,   98)(103,    97)(104,    98)(85  ,80)(91 ,86)(103,   97)(105,    98)
};
%\label{plot_two}
%\addlegendentry{id-05m-hor}

\addplot[
mark size=1.4pt,
only marks,
mark=o,
]
plot [error bars/.cd, y dir = both, y explicit]
coordinates {
(107,   100)(106,   100)(106,   99)(106,    99)(106,    99)(120,    97)(102,    95)(104,    97)(105,    98)
};
%\addlegendentry{id-05m-ver}

\addplot[
mark=o,
mark size=1.4pt,
only marks,
]
plot [error bars/.cd, y dir = both, y explicit]
coordinates {
(106,   98)(106,    98)(107,    99)(106,    98)(104,    86)(103,    97)(104,    98)(105,    99)(105,    97)
};
%\addlegendentry{id-15m-hor}
\addplot[
mark=o,
mark size=1.4pt,
only marks,
]
plot [error bars/.cd, y dir = both, y explicit]
coordinates {
(104,   97)(106,    99)(105,    98)(106,    98)(104,    98)(105,    98)(105,    98)(104,    98)(105,    88)
};
%\addlegendentry{id-15m-ver}
\addplot[
mark=o,
mark size=1.4pt,
only marks,
]
plot [error bars/.cd, y dir = both, y explicit]
coordinates {
(107,   97)(107,    95)(107,    90)(106,    96)(107,    97)(106,    96)(106,    97)(106,    96)(106,    96)(107,    55)(106,    97)(107,    96)
};
%\label{plot_two}
%\addlegendentry{od-05m-hor}
\addplot[
mark=o,
mark size=1.4pt,
only marks,
]
plot [error bars/.cd, y dir = both, y explicit]
coordinates {
(106,97)(106,97)(107,97)(107,95)(107,97)(107,97)(106,97)(107,95)(105,96)(107,97)(106,97)(107,97)
};
%\addlegendentry{od-05m-ver}

\addplot[
mark=o,
mark size=1.4pt,
only marks,
]
plot [error bars/.cd, y dir = both, y explicit]
coordinates {
(107,98)(107,97)(107,97)(106,97)(106,97)(106,97)(106,99)(107,99)(106,97)(104,99)(106,98)(106,49)
};
%\addlegendentry{od-15m-hor}
\addplot[
mark=*,
mark size=1.4pt,
only marks,
]
plot [error bars/.cd, y dir = both, y explicit]
coordinates {
(106,94)(107,97)(106,96)(107,97)(106,97)(106,97)(107,98)(107,96)(106,100)(102,96)(106,97)(106,99)
};
%\addlegendentry{od-15m-ver}

\end{axis}
\end{tikzpicture}
\end{figure}

Best Answer

Have a look at section 4.12 Error bars in the pgfplots manual.

When you say y explicit, you need to specify the error value for each point separately in the coordinate stream. For example

(107,100) +- (0,2)

indicates a y-error of 2 and x-error of 0. You must specify both I think, even if you only use the y-error.

But if you want to use the same error value for all the points in a plot, you can use y fixed=<value> instead of y explicit. For example,

\addplot+ [
   error bars/.cd,
   y dir=both,
   y fixed=1
] ...

gives you a y-error of 1 for all the points in the plot. But I don't think there is a built-in way of getting e.g. standard deviation of the plotted data, so if that is what you're after you need to calculate it first, and then use y fixed with the calculated value.

Unrelated comment:

Why do you use this?

\addplot [<some options>] plot[<other options>] ...

You're mixing pgfplots syntax with plain TikZ syntax, the correct would by to have all the options in the same set of brackets, and not use the plot keyword, i.e.

\addplot [<all options>] ...