Color areas between two curves and the x and y-axis (not polynomial)
Afficher commentaires plus anciens
I have two functions of one variable (p). I am trying to color the areas on the right of each curve. I succeed in doing this on a separate figure for each curve. I want to put those two curves on the same graph. When I try to do this, somehow it is the area on the left of the red curve that is shaded instead of the area of the right side of the red curve.
p = 0:0.001:1;
curve1 = ((3.*p)-2)./p
curve5 = 1./(2.*p);
ax1 = axes;
figure(1)
hold(ax1, 'on')
hold on
plot(p, curve1, 'LineWidth', 1.5,'linestyle','-','color',[0 0.4470 0.7410]);
hold on;
xlim([0 1]);
ylim([0 1]);
grid on;
lowerboundary = min(ylim(ax1));
area(curve1,lowerboundary,'FaceColor','b','FaceAlpha',0.2);
hold on
area(p,curve1,'FaceColor','b','FaceAlpha',0.2);
ax=gca;
figure(2)
hold(ax1, 'on')
hold on
plot(p, curve5, 'LineWidth', 1.5,'linestyle','-','color',[0.6350 0.0780 0.1840]);
hold on;
xlim([0 1]);
ylim([0 1]);
grid on;
upperboundary = max(ylim(ax1));
area(p,curve5,'FaceColor','r','FaceAlpha',0.2);
hold on
area(curve5,upperboundary,'FaceColor','r','FaceAlpha',0.2);
ax=gca;
figure(3)
hold(ax1, 'on')
hold on
plot(p, curve5, 'LineWidth', 1.5,'linestyle','-','color',[0.6350 0.0780 0.1840]);
hold on
plot(p, curve1, 'LineWidth', 1.5,'linestyle','-','color',[0 0.4470 0.7410]);
xlim([0 1]);
ylim([0 1]);
grid on
upperboundary = max(ylim(ax1));
lowerboundary = min(ylim(ax1));
area(curve5,upperboundary,'FaceColor','r','FaceAlpha',0.2);
hold on
area(p,curve5,'FaceColor','r','FaceAlpha',0.2);
hold on
area(curve1,lowerboundary,'FaceColor','b','FaceAlpha',0.2);
hold on
area(p,curve1,'FaceColor','b','FaceAlpha',0.2);
ax=gca;
Here are the outputs for the respectively figure 1, 2 and 3. My goal is to have on figure 3 the red color area on the right side of the red line, as if figures 1 and 2 were superposed/merged.



Any help would be appreciated!
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Data Distribution Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


