# How to Shade area between 3 curves each with different x-axis values?

8 ビュー (過去 30 日間)
Remy Benais-Thomson 2023 年 11 月 28 日
コメント済み: Voss 2023 年 11 月 28 日
I have experimental testing results: three curves and the y-axis data for each of the three curves don't follow the same x-axis values.
Looks like this:
I want to to be able to represent this data something like this (crudely done in paint just to show as an example):
I have my data in excel at the moment but plan to make the graphs in Matlab since they'll look better that way, and hoping I can accomplish this too.
I attached the raw data in an excel sheet in case someone wants to fiddle with it.
Thanks!

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

### 採用された回答

Voss 2023 年 11 月 28 日
I guess you want to shade the area between the lowest curve and the highest curve for all x.
T = 123×8 table
x y Var3 x_1 y_1 Var6 x_2 y_2 ________ ________ ____ ________ _________ ____ _______ _________ 0 0 NaN 0 0 NaN 0 0 0.063714 0.028959 NaN 0.082254 0.0041548 NaN 0.10554 0.016509 0.12306 0.038507 NaN 0.10867 0.010881 NaN 0.17314 0.0264 0.21075 0.048142 NaN 0.19174 0.017103 NaN 0.25046 0.035609 0.37736 0.054981 NaN 0.25649 0.023191 NaN 0.31436 0.045147 0.57239 0.060375 NaN 0.35343 0.029006 NaN 0.42199 0.052478 0.76991 0.060135 NaN 0.44538 0.035585 NaN 0.62686 0.054852 0.94001 0.056641 NaN 0.54134 0.042223 NaN 0.82456 0.0536 1.123 0.059891 NaN 0.6451 0.047708 NaN 1.0212 0.050263 1.3439 0.062615 NaN 0.74738 0.055775 NaN 1.2452 0.047925 1.5328 0.066984 NaN 0.88017 0.061894 NaN 1.4317 0.046652 1.7203 0.068182 NaN 1.0269 0.068091 NaN 1.6436 0.046194 1.8108 0.061031 NaN 1.1788 0.071225 NaN 1.8483 0.044618 1.9218 0.054251 NaN 1.3321 0.07262 NaN 2.0029 0.0058441 1.9353 0.062667 NaN 1.4768 0.068387 NaN 2.0163 0.04662 1.9873 0.031985 NaN 1.5956 0.062938 NaN 2.0219 0.03331
% create a common x vector:
x_all = [T.x,T.x_1,T.x_2];
x_min = min(x_all,[],'all');
x_max = max(x_all,[],'all');
x = linspace(x_min,x_max,1000);
% interpolate y, y1, and y2, based on the common x
% (there are some NaNs and/or Infs in some of the ys, so the
% interpolation needs to be done just using the finite values):
idx = isfinite(T.x) & isfinite(T.y);
y = interp1(T.x(idx),T.y(idx),x);
idx = isfinite(T.x_1) & isfinite(T.y_1);
y_1 = interp1(T.x_1(idx),T.y_1(idx),x);
idx = isfinite(T.x_2) & isfinite(T.y_2);
y_2 = interp1(T.x_2(idx),T.y_2(idx),x);
% get the min and max y for each x:
y_min = min([y;y_1;y_2],[],1);
y_max = max([y;y_1;y_2],[],1);
% create a patch to fill the area:
patch(x([1:end end:-1:1]),[y_min, y_max(end:-1:1)],'b','FaceAlpha',0.25,'EdgeColor','none')
% plot the original data lines:
hold on
plot(T.x,T.y,'.-',T.x_1,T.y_1,'.-',T.x_2,T.y_2,'.-')
##### 2 件のコメントなしを表示なしを非表示
Remy Benais-Thomson 2023 年 11 月 28 日
This is perfect! Thank you so much!
Voss 2023 年 11 月 28 日
You're welcome!

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

### カテゴリ

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

### Community Treasure Hunt

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

Start Hunting!

Translated by