在mathematica errorbar plot中突出显示适合区域

时间:2014-06-22 20:39:56

标签: wolfram-mathematica

我想在mathematica图中突出显示拟合区域,并在其上显示适当的拟合误差条。要用错误条绘制一些数据,我写了例如:

data={{{0, 0.00126517235028}, 
  ErrorBar[0.0097546177348]}, {{1, 0.0132870239578}, 
  ErrorBar[0.00717311242327]}, {{2, 0.00968907928987}, 
  ErrorBar[0.0125454440978]}, {{3, 0.00835906062474}, 
  ErrorBar[0.0196027916911]}, {{4, 0.0141038637039}, 
  ErrorBar[0.0288324766544]}, {{5, 0.0467626302256}, 
  ErrorBar[0.0423090450838]}, {{6, 0.0832535249208}, 
  ErrorBar[0.0609066442506]}};
ErrorListPlot[p0all67, Frame -> True, 
 PlotRange -> {{0, 6}, {0.3, -0.04}}, Axes -> False, 
 PlotStyle -> {AbsolutePointSize[10], AbsoluteThickness[2]}]

现在我使用线性拟合方法将数据拟合到另一个软件中,例如,x = 4到x = 6的拟合结果(或斜率)是0.0317349,误差条是0.0215005。我想用这个拟合值和误差突出显示拟合区域。所以我希望图形看起来像这样: hightlight

请问有人可以帮我怎么做?感谢。

1 个答案:

答案 0 :(得分:1)

Needs["ErrorBarPlots`"];

data = {{{0, 0.00126517235028}, 
    ErrorBar[0.0097546177348]}, {{1, 0.0132870239578}, 
    ErrorBar[0.00717311242327]}, {{2, 0.00968907928987}, 
    ErrorBar[0.0125454440978]}, {{3, 0.00835906062474}, 
    ErrorBar[0.0196027916911]}, {{4, 0.0141038637039}, 
    ErrorBar[0.0288324766544]}, {{5, 0.0467626302256}, 
    ErrorBar[0.0423090450838]}, {{6, 0.0832535249208}, 
    ErrorBar[0.0609066442506]}};

elp = ErrorListPlot[data, Frame -> True, 
   PlotRange -> {{0, 6}, {-0.05, 0.18}}, Axes -> False, 
   PlotStyle -> {AbsolutePointSize[7], AbsoluteThickness[1]}, 
   PlotRangePadding -> {0.4, 0}];

m = 0.0317349;
line[x_, c_] := m x + c;
{x4, y4} = data[[5, 1]];
ytest = line[x4, 0];
c = y4 - ytest;
check = line[x4, c];
x6 = 6;
y6 = line[x6, c];
delta = 0.0215005;
a = {{x4, y4 + delta}, {x6, y6 + delta}};
b = {{x4, y4 - delta}, {x6, y6 - delta}};

Show[elp,
 ListLinePlot[{{x4, y4}, {x6, y6}}, PlotStyle -> Thick], 
 ListLinePlot[{a, b}, Filling -> {1 -> {2}}, PlotStyle -> None],
 ImageSize -> 500]

enter image description here

以下是基于您的数据演示一些统计函数的示例。

data = {0.00126517235028, 0.0132870239578, 0.00968907928987,
   0.00835906062474, 0.0141038637039, 0.0467626302256, 0.0832535249208};

lm = LinearModelFit[data, {1, x , x^2, x^3}, x];

{sd1, sd2} = 2*(CDF[NormalDistribution[0, 1], #] - 0.5) & /@ {1, 2};

intervals = Flatten[Transpose /@ Table[
     lm["SinglePredictionConfidenceIntervals", ConfidenceLevel -> cl],
     {cl, {sd1, sd2}}], 1];

{bands68[x_], bands95[x_]} = Table[
   lm["SinglePredictionBands", ConfidenceLevel -> cl], {cl, {sd1, sd2}}];

Show[ListPlot[data, PlotMarkers -> Automatic], ListPlot[intervals],
 Plot[{lm[x], bands68[x], bands95[x]}, {x, 5, 8}, Filling -> {2 -> {1}, 3 -> {2}}],
 PlotRange -> {{1, 7}, {-0.02, 0.1}}, ImageSize -> 480, Frame -> True, Axes -> False]

enter image description here