Dashed confidence intervals and xlabel
1 回表示 (過去 30 日間)
古いコメントを表示
Today is my "plot day". I am trying to fit subplot with shaded confidence intervals (find the dataset attached). Besides, I have also a problem with xlabel. Let me write the code that is easier:
% data
data = xlsread('Q.xls')
lines = data(:,1:5)
lower_bound = data(:,6:10)
upper_bound = data(:,11:15)
k = 5
for j = 1:k
subplot(3, 2, j);
plot(lines(:,j), 'LineWidth',1,'Color', [0 0 0.5]);
hold on
fill(lower_bound(:,j), upper_bound(:,j), 'r', 'FaceAlpha', .1, 'EdgeColor', 'none');
xlabel('months');
yline(0, '-')
end
I also tried to use 'patch' but it didn't work either. What am I doing wrong? Besides, I would like 'xlabel' to be displayed only at the end of the first and second column; now, instead, it appears belowe every graph.
Can anyone help me fix this?
0 件のコメント
採用された回答
Star Strider
2020 年 5 月 31 日
To plot as you want to plot, you need to create an ‘x’ vector to plot against. Since you are plotting against the row indices, create it to do just that. After that, use the ‘usual’ format for the patch calls. The xlabel call requires an if block (that may need to be revised if you add more plots).
The (Slightly-Revised) Code —
data = xlsread('Q.xls')
lines = data(:,1:5);
lower_bound = data(:,6:10);
upper_bound = data(:,11:15);
x = (1:size(data,1)).'; % Create ‘x’ To Plot Correctly
k = 5
for j = 1:k
subplot(3, 2, j);
plot(x, lines(:,j), 'LineWidth',1,'Color', [0 0 0.5]);
hold on
patch([x; flipud(x)], [lower_bound(:,j); flipud(upper_bound(:,j))], 'r', 'FaceAlpha', .1, 'EdgeColor', 'none');
if (j >= 4)
xlabel('months');
end
yline(0, '-')
end
The Plot —
2 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!