How do I fill the area between two plots in a loglog plot?
2 次查看(过去 30 天)
显示 更早的评论
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
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')
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!