Patch and fill functions are not shading area between confidence intervals in 2024a
35 次查看(过去 30 天)
显示 更早的评论
I am trying to fill the area between two confidence intervals in Matlab 2024a. It is a depth-temperature chart where depth is Y and the confidence intervals are an upper and lower temperature bound in X. I have searched everything online, tried many things, and do not understand why the lines of the upper and lower bound will appear, but the area between the confidence intervals will not shade when calling both patch() and fill(). Here is a bit of my code:
clf;
plot(meanT, Depth, "r-", 'LineWidth', 2)
hold on
patch([Tlower; fliplr(Tupper)], [Depth; fliplr(Depth)], 'g')
Depth, meanT, Tlower, Tupper are all [nx1]. I have tried changing fliplr to flipud or just flip with no success. I have also tried transforming Tupper/Tlower to be sorted so they are smallest-to-largest and calling patch()/fill() on the sorted values. Same issue occurs. Any help to resolve this is much appreciated.
0 个评论
采纳的回答
Voss
2024-8-7,16:34
编辑:Voss
2024-8-7,16:36
This will work regardless of the orientation of the vectors, i.e., whether each is a row or column vector:
patch([Tlower(:); flipud(Tupper(:))], [Depth(:); flipud(Depth(:))], 'g')
assuming Depth is sorted (either way).
Running an example with random data (note that you need to plot the patch before the mean line in order to see the mean line on top of the patch, or else use a patch with some transparency):
Depth = 1:10;
meanT = rand(10,1);
Tlower = meanT.'-1;
Tupper = meanT+1;
whos Depth *T* % some are row vectors and some are column vectors
figure
patch([Tlower(:); flipud(Tupper(:))], [Depth(:); flipud(Depth(:))], 'g')
hold on
plot(meanT, Depth, "r-", 'LineWidth', 2)
If this doesn't give the expected result, then please save your variables to a mat file and upload it here using the paperclip button.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!