Message Boards Message Boards

0
|
5006 Views
|
1 Reply
|
1 Total Likes
View groups...
Share
Share this post:

[?] Combine ErrorListPlot and ErrorBar(x,y) for a lot of datapoints?

Posted 7 years ago

Hello!

I'm trying to Plot some data points with their x- and y-error.

So lets say i have two datasets with their errors:

x = {1, 2, 3};
y = {1, 4, 9};
xerror = {0.2, 0.2, 0.3};
yerror = {0.1, 0.4, 0.8};

Then I combine them to get a dataset I can plot:

dataset1 = Transpose[{x[[All]], y[[All]], yerror[[All]]}];
ErrorListPlot[dataset1]

Which gives me a nice Plot with the y-errors. However, if I want to add x-errors too I have to do the following:

ErrorListPlot[{{{1, 1}, ErrorBar[0.2, 0.1]}, {{2, 4}, ErrorBar[0.2, 0.4]}, {{3, 9}, ErrorBar[0.3, 0.8]}}]

It also works pretty well, however it is a lot of work if i do not have 3 datapoints but 60. So is there a way to do this faster? I thought of something like

dataset2 = Transpose[{x[[All]], y[[All]], ErrorBar[xerror[[All]], yerror[[All]]]}];
ErrorListPlot[dataset2]

Of course this is not working, but I think it kind of represents what I'd like to do. Do you guys know how to solve this problem?

Best regards,

Tobias

POSTED BY: Epsilon Tau

You can do this:

dataset1 = 
 MapThread[{{#1, #2}, ErrorBar[#3, #4]} &, {x, y, xerror, yerror}]
ErrorListPlot[dataset1]

Regards,

Neil

POSTED BY: Neil Singer
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract