2
$\begingroup$

I have a dataset like this:

data = 
  {{3.17, 2.41*^10}, {4.43, 2.37*^10}, {5.54, 2.27*^10}, {6.87, 2.15*^10}, 
   {8.52, 1.98*^10}, {10.5, 1.85*^10}, {13.14, 1.8*^10},{14.74, 1.81*^10}};

and I want to plot them via ListLogPlot.

Now, I would like to show 10% uncertainty in x and 5% uncertainty in y. I know, I can use the Around function for this. Written out by hand it looks like this:

data2 = 
  {{Around[3.17, Scaled[0.1]], Around[2.41*^10, Scaled[0.05]]}, 
   {Around[4.43, Scaled[0.1]], Around[2.37*^10, Scaled[0.05]]}, 
   {Around[5.54, Scaled[0.1]], Around[2.27*^10, Scaled[0.05]]}, 
   {Around[6.87, Scaled[0.1]], Around[2.15*^10, Scaled[0.05]]}, 
   {Around[8.52, Scaled[0.1]], Around[1.98*^10, Scaled[0.05]]}, 
   {Around[10.5, Scaled[0.1]], Around[1.85*^10, Scaled[0.05]]}, 
   {Around[13.14, Scaled[0.1]], Around[1.8*^10, Scaled[0.05]]}, 
   {Around[14.74, Scaled[0.1]], Around[1.81*^10, Scaled[0.05]]}};

With ListLogPlot[data2], I get the a plot:

enter image description here

Is there any way to automatize the definition of the 2nd dataset? My actual datssets are much larger, and I have many of them. I assume something like Map could be used.

I'm open for any idea. Maybe there is even a more elegant way directly in the ListLogPlot function.

$\endgroup$
1
  • 3
    $\begingroup$ Using ReplaceAll, consider: data /. {x_, y_} :> {Around[x, Scaled[0.1]], Around[y, Scaled[0.05]]} $\endgroup$
    – ktm
    Jan 24, 2020 at 21:41

2 Answers 2

3
$\begingroup$

You can use MapThread for this. Like so:

data = 
  {{3.17, 2.41*^10}, {4.43, 2.37*^10}, {5.54, 2.27*^10}, {6.87, 2.15*^10}, 
   {8.52, 1.98*^10}, {10.5, 1.85*^10}, {13.14, 1.8*^10},{14.74, 1.81*^10}};
MapThread[{Around[#1, Scaled[0.1]], Around[#2, Scaled[0.05]]} &, Transpose[data]]
{{3.17 ± 0.32, (2.41±0.12)×10^10}, {4.4±0.4, (2.37±0.12)×10^10},
 {5.5±0.6, (2.27±0.11)×10^10}, {6.9±0.7, (2.15±0.11)×10^10},
 {8.5±0.9, (1.98±0.10)×10^10}, {10.5±1.1, (1.85±0.09)×10^10},
 {13.1±1.3, (1.80±0.09)×10^10}, {14.7±1.5, (1.81±0.09)×10^10}}
$\endgroup$
1
$\begingroup$
ClearAll[threadAround]
threadAround = Thread @* MapThread[Thread[Around[#, Scaled @ #2]] &]@{Transpose[#], #2} &;

Example:

data = {{3.17, 2.41*^10}, {4.43, 2.37*^10}, {5.54, 2.27*^10}, {6.87, 2.15*^10},
  {8.52, 1.98*^10}, {10.5, 1.85*^10}, {13.14, 1.8*^10}, {14.74, 1.81*^10}};

threadAround[data, {.1, .05}]

enter image description here

Alternatively,

ClearAll[threadAround2]
threadAround2[d_, s_] := MapThread[Thread[Around[{##}, Scaled /@ s]] &]@Transpose[d]

threadAround2[data, {.1, .05}] == threadAround[data, {.1, .05}]

True

$\endgroup$
1
  • $\begingroup$ I like the idea with the function. But I don't understand your threadAround2, this function produces asymmetric errors. $\endgroup$
    – Lea
    Jan 26, 2020 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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