Patch and fill functions are not shading area between confidence intervals in 2024a
35 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Voss
le 7 Août 2024 à 16:34
Modifié(e) : Voss
le 7 Août 2024 à 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.
6 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Lighting, Transparency, and Shading 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!