필터 지우기
필터 지우기

How do I fill the area between two plots in a loglog plot?

조회 수: 3 (최근 30일)
Larissa Perez
Larissa Perez 2019년 10월 31일
댓글: Star Strider 2019년 11월 4일
I am trying to fill in the area between the confidence interval of my pwelch. This is the code I am using:
[px1, f, conf1] = pwelch(det_total_b1,hanning(nfft),round(0.5*nfft),nfft,fs,'ConfidenceLevel',0.95);
[px2, f, conf2] = pwelch(det_total_b2,hanning(nfft),round(0.5*nfft),nfft,fs,'ConfidenceLevel',0.95);
[px3, f, conf3] = pwelch(det_total_b3,hanning(nfft),round(0.5*nfft),nfft,fs,'ConfidenceLevel',0.95);
[px4, f, conf4] = pwelch(det_total_b4,hanning(nfft),round(0.5*nfft),nfft,fs,'ConfidenceLevel',0.95);
loglog (f,px1,'Color',[0 204/256 102/256])
hold on
loglog (f,px2,'Color',[1 102/256 102/256])
loglog (f,px3,'Color',[0 128/256 1])
loglog (f,px4,'Color',[1 153/256 51/256])
patch([f fliplr(f)],[conf1(:,1) fliplr(conf1(:,2))],[0.85 0.85 0.85])
set(gca, 'XScale', 'log', 'YScale','log')
But instead of filling the area in gray, what it does is plotting the confidence interval limits as black lines (figure attached). I can't understand why it is doing that.
Thanks for the help in advance!
  댓글 수: 2
Star Strider
Star Strider 2019년 10월 31일
I can’t run your code:
Unrecognized function or variable 'det_total_b1'.
Larissa Perez
Larissa Perez 2019년 10월 31일
Hi, thanks for the quick feedback.
det_total_b1 is my data. It is just a detrended time-series. I guess you can run it by creating a random time-series, just to check if the patch works?

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2019년 10월 31일
You have one fundamental error. Your matrices are (Nx2), so using fliplr on each column is pointless. You need to use flipud and vertically concatenate them:
patch([f; flipud(f)],[conf1(:,1); flipud(conf1(:,2))],[0.85 0.85 0.85]);
Perhaps the problem is with your data or what you are plotting, although when I simulated it with random (rand) column vectors, the data were real and greater than zero.
Using patch with loglog plots works in other contexts, for example:
x = sort(rand(10, 1));
y = sort(rand(10, 1));
figure
patch([x; flipud(x)], [y; flipud(y+0.2)], 'r')
set(gca, 'XScale','log', 'YScale','log')
  댓글 수: 2
Larissa Perez
Larissa Perez 2019년 11월 4일
Great, thanks!
It was something silly, I had 0 as part of f. That's why..
Star Strider
Star Strider 2019년 11월 4일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by