How to create a filling/shading between prediction bounds?

5 visualizaciones (últimos 30 días)
Hello,
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).
S=[0.95,0.87,0.83,0.73,0.62,0.51,0.41,0.31,0.22,0.04,0.002,0,0,0,0];
t=[1,3,5,10,20,30,40,50,60,90,120,180,240,360,1440];
hold on
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],...
'LineWidth',1.5);
p11 = predint(model,x,0.95,'observation','on');
plot(x,p11,'--','Color',[0.4235, 0.9608, .6],...
'LineWidth',1.5);
%Patch
%patch([x; flipud(x)], [flipud(p11(:,1)');flipud(p11(:,2)')], [0.4235, 0.9608, .6], 'EdgeColor','none','FaceAlpha',0.1);
%Fill
%fill(x, p11,p11,'facecolor', 'red', 'edgecolor', 'none', 'facealpha', 0.4);
legend
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?

Respuesta aceptada

Steve Eddins
Steve Eddins el 26 de En. de 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.
  2 comentarios
David Nielsen-Franco
David Nielsen-Franco el 27 de En. de 2022
Thanks for your answer Steve. I did try to set the EdgeColor to none, sadly, nothing shows.
I ran this:
patch([x; flipud(x)], [flipud(p11(:,1)');flipud(p11(:,2)')], [0.4235, 0.9608, .6], 'EdgeColor','none','FaceAlpha',0.1);
Steve Eddins
Steve Eddins el 27 de En. de 2022
If you set the EdgeColor to none and nothing shows, that suggests to me that my hypothesis is correct: your patch geometry is set up so that you have a huge number of patch edges that run back and forth between the curves. I'll repeat my suggestion to reorganize 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.
It would be helpful (to people trying to answer your question) if you would revise your code so that it can be run by others.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by