# Preparing data for making an ErrorListPlot

I often have the following notebook in Mathematica, which I use to make a dataset and associated errors:

x = {0, 2, 4, 6, 10, 20};
y = {979, 146, 141, 157, 187, 274};
uncY = Sqrt[y];


I want to make an ErrorListPlot, so I need to add ErrorBar with each uncY-value as an element in each data pair. So the final dataVector should have the form

{{x_i, y_i}, Errorbar[uncY_i]}


What is an easy way to achieve this, without using a For-loop?

-
@andre why is that? is it too specific? – BillyJean Mar 23 '13 at 21:29

If your errors input has the form :

errorList = {1, 2, 1, 3, 1, 2}


Then do :

Thread[{dataVector, Errorbar /@ errorList}]

(* {
{{0, 979}, Errorbar[1]},
{{2, 146}, Errorbar[2]},
{{4, 141}, Errorbar[1]},
{{6, 157}, Errorbar[3]},
{{10, 187}, Errorbar[1]},
{{20, 274}, Errorbar[2]}
} *)

-

I accidentally discovered that you can use convenient notation PlusMinus(±) for horizontal and vertical axes

ypm = Thread[y ± uncY]


ErrorListPlot[Thread[{x, ypm}]]


In your case you can use even more simple method as mentioned here:

ErrorListPlot[Thread[{x, y, uncY}]]


Unfortunately, these nice options are still undocumented.

-

You can do all the manipulation in one line if you wish:

ErrorListPlot@MapThread[{{#1, #2}, ErrorBar[#2-uncY@#2 ]} &, {x, y}]

-
I would thumb-up if I had sufficient reputation – BillyJean Mar 23 '13 at 21:30
I'll take a virtual thumbs up, cheers ;) – image_doctor Mar 24 '13 at 0:32