MATLAB Answers


plotting the confidence bands

Asked by dy10
on 11 Jun 2019
Latest activity Commented on by Star Strider
on 11 Jun 2019
I am trying to plot z with confidence intervals (lo and hi). I have years between 1993-2000 on my x-axis. If I don't include the last two lines (which specifies my year values) in my command, the code runs fine. However, with last 2 lines, the plot dissapears. How can I add the values?
z=[0.07 0.24 0.25 0.09 -0.25 -0.56 -1.07 -1.28]
x = 1:8;
lo = z - 0.3;
hi = z + 0.3;
hp = patch([x; x(end:-1:1); x(1)], [lo; hi(end:-1:1); lo(1)], 'r');
hold on;
h= line(x,z);
set(gca, 'XLim', [1993 2000])
set(gca, 'XTick', [1993:2000], 'FontSize',8)


Sign in to comment.

1 Answer

Answer by Star Strider
on 11 Jun 2019
Edited by Star Strider
on 11 Jun 2019

I can’t run your code because the patch call you posted is corrupt.
Try this in place of your set calls:
xt = get(gca, 'XTick');
set(gca, 'XTick',xt, 'XTickLabel',t)
Fixing the patch call and with these get and set calls produces:
plotting the confidence band - 2019 06 11.png
EDIT — Added plot figure.


Show 1 older comment
My pleasure.
Change thes assignments:
xt = get(gca, 'XTick');
set(gca, 'XTick',xt, 'XTickLabel',t)
xt = get(gca, 'XTick');
xtv = linspace(min(xt), max(xt), numel(t));
set(gca, 'XTick',xtv, 'XTickLabel',t)
That should also work for any other changes you make to the tick label vector.
You may also have to reduce the font size of the tick labels, or rotate them, since they are now much closer together.
Thank you. I really appreciate it.
My pleasure.
If my Answer helped you solve your problem, please Accept it!

Sign in to comment.