plotting the confidence bands
Ältere Kommentare anzeigen
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)
Antworten (1)
Star Strider
am 11 Jun. 2019
Bearbeitet: Star Strider
am 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:

EDIT — Added plot figure.
4 Kommentare
Star Strider
am 11 Jun. 2019
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
am 11 Jun. 2019
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
am 11 Jun. 2019
Star Strider
am 11 Jun. 2019
My pleasure.
If my Answer helped you solve your problem, please Accept it!
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!