フィルターのクリア

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