2
$\begingroup$

I want to make a scatter plot using two huge lists that give the $x$ and $y$ coordinates of the points. To each $(x,y)$ point I want to add a symmetric errorbar (I have anothe list with the errors) in the $y$ direction.

I know the solution to this problem following the instructions given in this link. The problem is that the fact that my lists are huge makes doing this by hand tedious.

Is there a way to implement this method in a more effective way rather than introducing the command suggested in the link I have provided by hand for all points?

$\endgroup$
5
$\begingroup$

Given that you have three lists with data, one for the x coordinates, one for the y coordinates and one for the error bar, this is pretty easy. We just have to generate a new list where every element is picked from corresponding positions of the respective lists.

This combined list is then turned into the {{x, y}, ErrorBar[error]} triplet required by ErrorListPlot.

Needs["ErrorBarPlots`"]

x = {1, 2, 3, 4};
y = {2, 4, 6, 8};
e = {1, 2, 3, 4}/5;

ErrorListPlot[{{#1, #2}, ErrorBar[#3]} & @@@ Transpose[{x, y, e}]]

Mathematica graphics

$\endgroup$
  • $\begingroup$ and how could I use this method to make a plot with two data sets, x1,y1,e1 and x2,y2,e3? $\endgroup$ – PhoenixPerson Apr 17 '15 at 9:04
  • $\begingroup$ ErrorListPlot[{ {{#1, #2}, ErrorBar[#3]} & @@@ Transpose[{x1, y1, e1}], {{#1, #2}, ErrorBar[#3]} & @@@ Transpose[{x2, y2, e3}]] $\endgroup$ – Sjoerd C. de Vries Apr 17 '15 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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