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 —
更多回答(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!