plotting the confidence bands

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;
x=x';
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)

回答 (1 件)

Star Strider
Star Strider 2019 年 6 月 11 日
編集済み: Star Strider 2019 年 6 月 11 日

0 投票

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.

4 件のコメント

Star Strider
Star Strider 2019 年 6 月 11 日
dy10’s Answer moved here:
Thank you for your quick response. Your suggestion works perfectly!
Now I extended the estimation period through 2006. I didn't change anything in the code other then adding new estimated values to the z-vector, re-defining t=[1993:2006] and x = 1:14
I am still having problmes with x-axis. All the data points are in the plot, but x-axis ends with 2000. I believe this is due to incorrect spacing. And plot looks like it's been cut of at the begining.
z=[0.05 0.14 0.15 0.11 0.050 -0.06 -0.29 -0.58 -0.69 -0.75 -0.77 -0.8 -0.85 -0.9]';
x = 1:14;
x=x';
lo = z - 0.3;
hi = z + 0.3;
t=[1993:2006];
hp = patch([x; x(end:-1:1); x(1)], [lo; hi(end:-1:1); lo(1)], 'r');
hold on;
hl = line(x,z);
xt = get(gca, 'XTick');
set(gca, 'XTick',xt, 'XTickLabel',t)
Star Strider
Star Strider 2019 年 6 月 11 日
My pleasure.
Change thes assignments:
xt = get(gca, 'XTick');
set(gca, 'XTick',xt, 'XTickLabel',t)
to:
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.
dy10
dy10 2019 年 6 月 11 日
Thank you. I really appreciate it.
Star Strider
Star Strider 2019 年 6 月 11 日
My pleasure.
If my Answer helped you solve your problem, please Accept it!

サインインしてコメントする。

カテゴリ

質問済み:

2019 年 6 月 11 日

コメント済み:

2019 年 6 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by