How to create a filling/shading between prediction bounds?
2 views (last 30 days)
David Nielsen-Franco on 26 Jan 2022
I have some data fitted to an exponential function (y1) using the curve fitting app to calculate the coefficients. I then imported the model and the prediction intervals (p11; a 1441x2 matrix).
s2=scatter(t,S,250,[0.1216, 0.8, 0.0157],'^','filled');
x = 0:1440;
y1 = 1.016*exp(-0.02349*x)
p1=plot(x,y1,'Color',[0.1216, 0.8, 0.0157],...
p11 = predint(model,x,0.95,'observation','on');
plot(x,p11,'--','Color',[0.4235, 0.9608, .6],...
%patch([x; flipud(x)], [flipud(p11(:,1)');flipud(p11(:,2)')], [0.4235, 0.9608, .6], 'EdgeColor','none','FaceAlpha',0.1);
%fill(x, p11,p11,'facecolor', 'red', 'edgecolor', 'none', 'facealpha', 0.4);
I want to have the area between the prediciton bounds/confidence intervals filled with a different color, but it seems I can only get a solid black shading using 'patch'.
I also tried using the 'fill' function but the polygons go all the way to the top of y axis. Is there a way to adjust the Edge thickness/color?
Steve Eddins on 26 Jan 2022
I can't completely run your code (s and Asiiimodel are missing), but I think that the black color in your patch result is from the patch edges. Your data inputs to patch may be arranged in such a way that the edges are zipping rapidly up and down between the two curves. You could test this hypothesis by setting EdgeColor to none in your call to patch.
I'd suggest reorganizing the x-y data in your call to patch so that the patch edges follow one curve and then the other, instead of going back and forth between them. Then you can set the FaceAlpha property to make your filling patch transparent.