Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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];
dataVector = Thread[{x, 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?

share|improve this question
@andre why is that? is it too specific? – BillyJean Mar 23 '13 at 21:29
up vote 9 down vote accepted

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]}
 } *)
share|improve this answer

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

ErrorListPlot@MapThread[{{#1, #2}, ErrorBar[#2-uncY@#2 ]} &, {x, y}]
share|improve this answer
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

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

ypm = Thread[y ± uncY]

enter image description here

ErrorListPlot[Thread[{x, ypm}]]

enter image description here

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.