2014-06-22 225 views
2

我想在適當的合適誤差欄上突出顯示mathematica圖中的擬合區域。繪製與誤差棒一些數據I寫例如:在在mathematica errorbar plot中突出顯示擬合區域

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

+0

謝謝。這有很大幫助 – user3389597