使用函数形式绘制错误带

时间:2015-06-09 23:22:46

标签: wolfram-mathematica

我有一个包含x,y和error(y)值的数据集。我在mathematica中写道:

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

但是我想要获得的是绘制一条线并获得一个阴影错误带,连接符合函数形式f(x)= 0.05 + 0.02/(x^2 + 0.425)的错误栏。我不想明确地显示错误栏,而是想显示乐队。我正在寻找像这样的Desired plot

我看过这个链接http://reference.wolfram.com/language/howto/GetResultsForFittedModels.html 但无法解决问题。有人可以帮帮我吗?谢谢。

1 个答案:

答案 0 :(得分:2)

这是一种方法,制作两个列表,一个列表用于错误的上限:

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}};

错误范围较小的另一个列表为:

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}}; 

一旦你有两套,你可以使用 ListPlot 选项:

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

将生成类似enter image description here

的图表

如果您想加入它们,请使用 ListLinePlot 选项

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

enter image description here

并在其间设置阴影区域,使用填充选项

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

enter image description here

要获得平滑的图形,您需要更多数据点。希望这会有所帮助。

要包含 BestFit 行,请定义一个函数并添加到上一个图中:

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