![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/174108/image.png)
How to fill the area between two line in a log log plot
64 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Mainul Hoque
le 16 Avr 2016
Commenté : Star Strider
le 22 Déc 2019
Hi,
I want to shade the area between the lower and upper curve. I attached the dat. file so you can use this. The following simple code has been used to generate the given figure.
load limit.dat
a=limit(:,1);
upper=limit(:,2);
lower=limit(:,3);
avg=limit(:,4);
loglog(a,avg,a,upper,a,lower)
Can anybody please come with an idea. Thanks in advance.
Cheers!!
Pavel
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/161419/image.jpeg)
0 commentaires
Réponse acceptée
Star Strider
le 16 Avr 2016
You need to edit your data to be only those greater than zero (negative and zero values will not plot on a loglog plot anyway, so you lose nothing by eliminating them), then a simple patch call works:
fidi = fopen('Mainul Hoque limit.txt','r');
limitc = textscan(fidi, '%f%f%f%f', 'CollectOutput',1);
limit = limitc{:};
a=limit(:,1);
upper=limit(:,2);
lower=limit(:,3);
avg=limit(:,4);
idx = upper>0 & lower>0 & avg>0; % Eliminate Negative & Zero Data
figure(1)
patch([a(idx)' fliplr(a(idx)')], [lower(idx)' fliplr(upper(idx)')], [0.8 0.8 0.8])
hold on
plot(a(idx),avg(idx), a(idx),upper(idx), a(idx),lower(idx))
hold off
set(gca, 'XScale', 'log', 'YScale','log')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/174108/image.png)
I used a light gray triple [0.8 0.8 0.8] for the fill colour. Use whatever colour works for you.
6 commentaires
Samuel diabate
le 22 Déc 2019
I focussed on the PSD vector and I didn't think about checking the frequency vector. It works great now, with your help.
Thanks a lot and sorry for the inconvenience.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur 2-D and 3-D Plots 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!