Problem with fill / patch
26 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Catriona Fyffe
le 6 Mar 2021
Commenté : Star Strider
le 7 Mar 2021
Hi, I would like to use fill or patch to colour the space between two lines. I have a minimum value and a maximum value and both are plotted against a datetime vector. I have tried to follow carefully other instructions for using patch or fill but I am not getting what I expect - any ideas where I am going wrong? Many thanks!
%With fill and flip lr
x=[1:1:14568]'; %#initialize x array
y1=MC_all_light.SG_MC_light.SN_ICE_D_stats.min; %#create first curve
y2=MC_all_light.SG_MC_light.SN_ICE_D_stats.max; %#create second curve
X=[x,fliplr(x)]; %#create continuous x value array for plotting
Y=[y1,fliplr(y2)]; %#create y values for out and then back
figure();fill(X,Y,'b');
%Basically the same with patch and flipud. Here I am using DateTime, but I get the same results with a vector as for fill.
figure();
patch([datenum(SG_out.DateTime) flipud(datenum(SG_out.DateTime))], [MC_all_light.SG_MC_light.SN_ICE_D_stats.max flipud(MC_all_light.SG_MC_light.SN_ICE_D_stats.min)], [0.6 0.8 1.0])
The first graph is with fill the second with patch. I really want the colour to be between the max and min lines!
0 commentaires
Réponse acceptée
Star Strider
le 6 Mar 2021
It would help to have your data.
Try something like this:
x = linspace(0, 15000, 1000);
y1 = (500*rand(size(x))-1E-5*(7000-x).^2)*1E-2 + 54.5-x*1E-3;
y2 = (500*rand(size(x))-1E-5*(7000-x).^2)*1E-2 + 54.5-2*x*1E-3;
y1y2 = [y1; y2];
figure
plot(x, y1)
hold on
plot(x, y2)
fill([x fliplr(x)], [min(y1y2) fliplr(max(y1y2))], 'b')
hold off
If you want to colour between ther max and min values (and since it appears that both curves have the same number of points), tell fill to do just that! (If you are using datetime arrays, fill is preferable to patch, since patch will not work with datetime arrays.)
2 commentaires
Star Strider
le 7 Mar 2021
As always, my pleasure!
I am happy that I was able to help you solve your problem, even if indirectly!
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Polygons dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!