Dashed confidence intervals and xlabel

조회 수: 1 (최근 30일)
Armando MAROZZI
Armando MAROZZI 2020년 5월 31일
댓글: Star Strider 2020년 5월 31일
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?

채택된 답변

Star Strider
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
Armando MAROZZI
Armando MAROZZI 2020년 5월 31일
thanks so much! superb!
Star Strider
Star Strider 2020년 5월 31일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by