Plot error band using functional form

1.2k views Asked by At

I have a data set with x,y and error(y) values. I write this in mathematica as:

Needs["ErrorBarPlots`"]
data = {{{0, 0.10981309359605919}, 
    ErrorBar[0.05240427422664753`]}, {{0.2145, 0.09146326059113304}, 
    ErrorBar[0.034195343626358385`]}, {{0.4290, 0.08230438177339898}, 
    ErrorBar[0.02533205817067696`]}, {{0.6435, 0.0768141842364532}, 
    ErrorBar[0.020205473852635995`]}, {{0.8580, 0.07223473349753692}, 
    ErrorBar[0.016156209168991867`]}, {{4, 0.056122650246305375}, 
    ErrorBar[0.009288720442961331]}};
ErrorListPlot[data, Frame -> True, FrameStyle -> Directive[Black, 20],
  PlotRange -> {{-0.1, 5}, {0.2, 0}}, Axes -> False, 
 PlotStyle -> {Directive[Red, 12], AbsolutePointSize[10], 
   AbsoluteThickness[3]} , LabelStyle -> Directive[Green], 
 BaseStyle -> {Large, FontFamily -> "Courier", FontSize -> 12}]

errobarplot

But what I am trying to obtain is draw a line and get a shaded error band connecting the errorbars which obey a functional form, f(x)= 0.05 + 0.02/(x^2 + 0.425) . I don't want to show the error bars explicitly , rather I want to show the band. I am looking for something like this Desired plot

I have looked at this link http://reference.wolfram.com/language/howto/GetResultsForFittedModels.html but couldn't solve the problem. Could anyone please help me? Thanks.

1

There are 1 answers

0
string On BEST ANSWER

Here is one approach, make two lists, one list for upper range of the erros:

dataPLUS = {{0, 0.10981309359605919 + 0.05240427422664753`}, {0.2145, 
0.09146326059113304 + 0.034195343626358385`}, {0.4290, 
0.08230438177339898 + 0.02533205817067696`}, {0.6435, 
0.0768141842364532 + 0.020205473852635995`}, {0.8580, 
0.07223473349753692 + 0.016156209168991867`}, {4, 
0.056122650246305375 + 0.009288720442961331}};

another list for the lower range of the errors as:

dataMINUS = {{0, 0.10981309359605919 - 0.05240427422664753`}, {0.2145,
 0.09146326059113304 - 0.034195343626358385`}, {0.4290, 
0.08230438177339898 - 0.02533205817067696`}, {0.6435, 
0.0768141842364532 - 0.020205473852635995`}, {0.8580, 
0.07223473349753692 - 0.016156209168991867`}, {4, 
0.056122650246305375 - 0.009288720442961331}}; 

Once you have the two sets you can use the ListPlot option as:

ListPlot[{dataPLUS, dataMINUS}, PlotStyle -> Red, PlotRange -> All]

which will generate a graph like enter image description here

if you want to join them, instead use ListLinePlot option

ListLinePlot[{dataPLUS, dataMINUS}, PlotStyle -> Red,PlotRange -> All]

enter image description here

and to have a shaded region in between, use the Filling option

ListLinePlot[{dataPLUS, dataMINUS}, PlotStyle -> Red, Filling -> {1 -> {{2}, Gray}}, PlotRange -> All]

enter image description here

To get smooth graph, you need more data points. Hope this will help.

And to include the BestFit line, define a function and add to the previous plots as:

f[x_] = 0.05 + 0.02/(x^2 + 0.425);
plot2 = Plot[f[x], {x, 0, 5}, PlotStyle -> {Red, Thick}];
plot1 = ListLinePlot[{dataPLUS, dataMINUS}, PlotStyle -> LightGray,Filling -> {1 -> {{2}, LightGray}}, PlotRange -> All];
Show[{plot1, plot2}]

enter image description here