Bound fill between two bounds, data given

Hi. I have:
Upper Bound: UB = [5.522, 5.326, 5.250, 5.228, 5.198, 5.190];
Lower Bound: LB = [4.682, 4.874, 5.070, 5.069, 5.119, 5.122];
No. of elements: No = [388, 797, 1599, 3302, 6801, 13809];
I want to shade the area between those two bounds. I found answered questions to the same question, but I don't know how to translate it to my data. Also is there way to make the shaded area slightly opac or make it comprise of tiny dots? I have a couple of bounds and they might coincide. Also is there a way to add the shaded area to the legend (as shown on the picture)? Basically, I want to achieve something like this:
Man thanks for the help!
Lukasz

 Réponse acceptée

jonas
jonas le 10 Nov 2018
Modifié(e) : jonas le 10 Nov 2018
Should be easy using either fill or polygon. Just make sure you close the curve by flipping one of the bounds. For example:
UB = [5.522, 5.326, 5.250, 5.228, 5.198, 5.190];
LB = [4.682, 4.874, 5.070, 5.069, 5.119, 5.122];
No = [388, 797, 1599, 3302, 6801, 13809];
y = [UB flip(LB)];
x = [No flip(No)];
h = fill(x,y,'k','facealpha',0.1)
The output patch object of fill can be used as input to the legend.
You can use a FEX function for pattern fills, such as hatchfill. However, you will be able to distinguish overlapping areas if you play around with the facealpha argument of fill.

4 commentaires

Lukasz Skowron
Lukasz Skowron le 10 Nov 2018
Thanks, it does exactly what I want! However, I still some questions.
How can I insert markers to be shown on my bounds? Is there a way to do it within fill() or do I need to overlap it with another plot() using hold on? Where can I find all the options that go within fill()? The MatLab documentation is not very informative... I mean I want to change the countour to different color and in other graphs I want to get rid of it completely.
Thanks for the help!
jonas
jonas le 10 Nov 2018
Modifié(e) : jonas le 10 Nov 2018
fill creates a patch object and you can get all its properties by calling the patch handle that is output from fill, i.e.
h = fill(...)
get(h)
Or you can check the doc on patch properties. Some interesting properties would be edgecolor, facecolor and facealpha. You can always set a color to 'none' to make it invisible.
I'm not sure what you mean by "markers on your bounds". You can place markers on the patch edges by:
set(h,'marker','x')
The edges are basically line objects, so there is absolutely no reason to overlay lines/markers using plot. If you want a "pattern fill" then you have to use some FEX function.
Lukasz Skowron
Lukasz Skowron le 10 Nov 2018
Thank you a lot for the help!
jonas
jonas le 10 Nov 2018
Cheers!

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by