Replace lines with curved lines on my graph

2 ビュー (過去 30 日間)
Sam
Sam 2020 年 7 月 28 日
コメント済み: Sam 2020 年 7 月 29 日
I currently have a graph with two sets of data and their confidence intervals at 95%. However, I have been requested to change these lines to curved lines between the data points. I'm very new to Matlab, could anyone assist?
Here is the graph currently:
The code I am currently running:
x=[5,610,1115,1620,2125,2630,3135,3640,4145,4650];
y=[1.5728,1.6011,1.5828,1.583,1.5779,1.5931,1.6136,1.6132,1.6354,1.6512];
CI = [0.047204964 0.020555517 0.030005595 0.023338819 0.030057518 0.026567109 0.027295407 0.025855224 0.029278635 0.028793178]; %CI values
y2 = [1.4904,1.625,1.5834,1.6213,1.6135,1.6378,1.6212,1.6563,1.662,1.6657,1.6462,1.7267]
x2 = [5,610,1115,1620,2125,2630,3135,3640,4145,4650, 5155, 5660]
CI2 = [0,0.02859404,0.03932538,0.031767406, 0.033377728,0.033181883,0.02925182, 0.030260765,0.028698134,0.026206678,0.035101913,0]
plot(x, y, 'color', [0, .6, .77])
hold on
plot(x, y-CI, ':', 'color', [0, .6, .77])
hold on
plot(x , y+CI, ':','color', [0, .6, .77])
hold on
plot(x2, y2, 'color', [.89, 0, .23])
hold on
plot(x2, y2-CI2, ':', 'color', [.89, 0, .23])
hold on
plot(x2 , y2+CI2, ':','color', [.89, 0, .23])
patch([x fliplr(x)], [y-CI fliplr(y+CI)], [0.4, .76078, .85882], 'FaceAlpha',0.5, 'EdgeColor','none')
patch([x2 fliplr(x2)], [y2-CI2 fliplr(y2+CI2)], [.93, 0.4, .53], 'FaceAlpha',0.5, 'EdgeColor','none')
hold off
ylabel('vTMD')
xlabel('Depth (%)')
xticks([5, 610, 1115, 1620, 2125, 2630, 3135, 3640, 4145, 4650, 5155, 5660])
xticklabels({'0-5', '6-10', '11-15', '16-20', '21-25', '26-30', '31-35', '36-40', '41-45', '46-50', '51-55', '56-60'})
yticks([1.450 1.475 1.500 1.525 1.550 1.575 1.600 1.625 1.650 1.675 1.700 1.725 1.750
])
yticklabels({'1.450' '1.475' '1.500' '1.525' '1.550' '1.575' '1.600' '1.625' '1.650' '1.675' '1.700' '1.725' '1.750'
})

採用された回答

Alan Stevens
Alan Stevens 2020 年 7 月 29 日
Using spline curve fits perhaps:
x=[5,610,1115,1620,2125,2630,3135,3640,4145,4650];
y=[1.5728,1.6011,1.5828,1.583,1.5779,1.5931,1.6136,1.6132,1.6354,1.6512];
xx = 5:4650;
yy = spline(x,y,xx);
CI = [0.047204964 0.020555517 0.030005595 0.023338819 0.030057518 0.026567109 0.027295407 0.025855224 0.029278635 0.028793178]; %CI values
y2 = [1.4904,1.625,1.5834,1.6213,1.6135,1.6378,1.6212,1.6563,1.662,1.6657,1.6462,1.7267];
x2 = [5,610,1115,1620,2125,2630,3135,3640,4145,4650, 5155, 5660];
xx2 = 5:5660;
yy2 = spline(x2,y2,xx2);
CI2 = [0,0.02859404,0.03932538,0.031767406, 0.033377728,0.033181883,0.02925182, 0.030260765,0.028698134,0.026206678,0.035101913,0];
plot(xx, yy, 'color', [0, .6, .77])
hold on
yylo = spline(x,y-CI,xx);
plot(xx, yylo, ':', 'color', [0, .6, .77])
hold on
yyhi = spline(x,y+CI,xx);
plot(xx , yyhi, ':','color', [0, .6, .77])
hold on
plot(xx2, yy2, 'color', [.89, 0, .23])
hold on
yy2lo = spline(x2,y2-CI2,xx2);
plot(xx2, yy2lo, ':', 'color', [.89, 0, .23])
hold on
yy2hi = spline(x2,y2+CI2,xx2);
plot(xx2 ,yy2hi, ':','color', [.89, 0, .23])
patch([xx fliplr(xx)], [yylo fliplr(yyhi)], [0.4, .76078, .85882], 'FaceAlpha',0.5, 'EdgeColor','none')
patch([xx2 fliplr(xx2)], [yy2lo fliplr(yy2hi)], [.93, 0.4, .53], 'FaceAlpha',0.5, 'EdgeColor','none')
hold off
ylabel('vTMD')
xlabel('Depth (%)')
xticks([5, 610, 1115, 1620, 2125, 2630, 3135, 3640, 4145, 4650, 5155, 5660])
xticklabels({'0-5', '6-10', '11-15', '16-20', '21-25', '26-30', '31-35', '36-40', '41-45', '46-50', '51-55', '56-60'})
yticks([1.450 1.475 1.500 1.525 1.550 1.575 1.600 1.625 1.650 1.675 1.700 1.725 1.750
])
yticklabels({'1.450' '1.475' '1.500' '1.525' '1.550' '1.575' '1.600' '1.625' '1.650' '1.675' '1.700' '1.725' '1.750'
})
  1 件のコメント
Sam
Sam 2020 年 7 月 29 日
This is perfect, thank you so much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

タグ

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by