Plot two areas of logarithmic plots

3 vues (au cours des 30 derniers jours)
Adi Purwandana
Adi Purwandana le 14 Mai 2024
Commenté : Voss le 14 Mai 2024
Hello there,
I have two parameters that I want to plot them in one graph with area (transparent/alpha mode) for each of them as follow:
Here is my initial script (line plots):
load('data_x.mat')
figure;
plot(x1,y,'b','Linewidth',1);
hold on;
plot(x2,y,'r','Linewidth',1);
set(gca,'xscale','log','Ydir','reverse')
Warning: Negative data ignored
Does anyone know how to do that? Please find attached my data.
Thank you

Réponse acceptée

Voss
Voss le 14 Mai 2024
load('data_x.mat')
figure;
plot(x1,y,'b','Linewidth',1);
hold on;
plot(x2,y,'r','Linewidth',1);
set(gca,'xscale','log','Ydir','reverse')
x_lim = xlim();
Warning: Negative data ignored
x_p = x1;
x_p(~isfinite(x1) | x1 <= 0) = x_lim(1);
patch([x_p x_lim([1 1])],[y y([end 1])],'b','EdgeColor','none','FaceAlpha',0.25)
x_p = x2;
x_p(~isfinite(x2) | x2 <= 0) = x_lim(1);
patch([x_p x_lim([1 1])],[y y([end 1])],'r','EdgeColor','none','FaceAlpha',0.25)
  4 commentaires
Adi Purwandana
Adi Purwandana le 14 Mai 2024
Thank you!
Voss
Voss le 14 Mai 2024
You're welcome!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by