I have a question about using the area
function; or perhaps another function is in order...
I created this plot from a large text file:
The green and the blue represent two different files. What I want to do is fill in the area between the red line and each run, respectively. I can create an area plot with a similar idea, but when I plot them on the same figure, they do not overlap correctly. Essentially, 4 plots would be on one figure.
I hope this makes sense.
You can accomplish this using the function FILL to create filled polygons under the sections of your plots. You will want to plot the lines and polygons in the order you want them to be stacked on the screen, starting with the bottom-most one. Here's an example with some sample data:
And here's the resulting figure:
You can also change the stacking order of the objects in the figure after you've plotted them by modifying the order of handles in the
'Children'
property of the axes object. For example, this code reverses the stacking order, hiding the green polygon behind the blue polygon:Finally, if you don't know exactly what order you want to stack your polygons ahead of time (i.e. either one could be the smaller polygon, which you probably want on top), then you could adjust the
'FaceAlpha'
property so that one or both polygons will appear partially transparent and show the other beneath it. For example, the following will make the green polygon partially transparent:You want to look at the patch() function, and sneak in points for the start and end of the horizontal line:
If you only want the filled in area for a part of the data, you'll need to truncate the x and y vectors to only include the points you need.
Personally, I find it both elegant and convenient to wrap the fill function. To fill between two equally sized row vectors
Y1
andY2
that share the supportX
(and color C):Building off of @gnovice's answer, you can actually create filled plots with shading only in the area between the two curves. Just use
fill
in conjunction withfliplr
.Example:
By flipping the x array and concatenating it with the original, you're going out, down, back, and then up to close both arrays in a complete, many-many-many-sided polygon.