How to plot two different styles of confidence intervals in looped subplots?
Show older comments
I have a plot with 6 variables and 5 subplot. In one case, the third variable, I want it to display two lines in one graph. So far, it is fine. However, I also need confidence intervals to differ in shap for this subplot, the alternative ones should be dashaded while the others shaded. I don't know how to do it.
This is an example (data on attached excel file):
data = xlsread('prova.xls') % Data
lines = data(:, 1:5)
line2 = data(:, 16)
ci = data(:, 6:15)
ci2 = data(:,17:18)
k = 5 % plot
for j = 1:k
subplot(3, 2, j);
plot(lines(:,j), 'LineWidth',1,'Color', [0 0 0.5]);
hold on
if j == 3
plot(line2, 'LineWidth',1,'Color', [0 0 0.5], 'LineStyle','--')
end
hold on
plot(ci,'LineWidth',1,'Color', [0 0 0.5],'LineStyle','--');
hold on
% plot(ci2,'LineWidth',1,'Color', [0 0 0.5],'LineStyle','--'); % don't know how to plot it
% I tried: if j == 3
% plot(ci2, 'LineWidth',1,'Color', [0 0 0.5], 'LineStyle','--mo')
% end but it didn't work
yline(0, '-')
end
I would like the code to be modified to embed: a) the confidence intervals of the second dataset only in subplot 3; b) a different confidence interval's style (shaded vs dashed). I am stuck and don't know how to do it unfortunately.
Is there anyone who can help me?
Thanks!
7 Comments
It looks like you're plotting CIs as lines which doesn't make sense to me. Even if the lines are CI bounds, I'd explect to see upper and lower bounds. I understand that your data are 'fake data' and it's helpful that you've provided an example that we can run. But it's not clear how a line object can be shaded.
Armando MAROZZI
on 30 May 2020
Armando MAROZZI
on 30 May 2020
Adam Danz
on 30 May 2020
The '--mo' linestyle correctly throws an error. It should also throw an error for you. This isn't related to the main problem but it should be corrected. A linestye cannot contain the marker type or color. It can be changed to '--'.
Armando MAROZZI
on 30 May 2020
Adam Danz
on 30 May 2020
The updated demo is still confusing.
For example, instead of plotting ci as lines, I plotted them as circular markers and this is the first subplot. It's not clear how those markers are supposed to represent confidence intervals.

Armando MAROZZI
on 30 May 2020
Accepted Answer
More Answers (0)
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!