Code covered by the BSD License

### Highlights from Shade area between two curves

4.52273
4.5 | 46 ratings Rate this file 64 Downloads (last 30 days) File Size: 1.75 KB File ID: #13188 Version: 1.1

# Shade area between two curves

### John Bockstege (view profile)

30 Nov 2006 (Updated )

Function shades the area between two vectors.

File Information
Description

This routine will shade the area of a 2-D plot between two user defined vectors. Simply pass the two vectors, and their corresponding horizontal coordinates, select your fill color and transparency level and viola! You have a figure that is colored in between the two input vectors.

Acknowledgements
MATLAB release MATLAB 7.3 (R2006b)
22 Jul 2016 Ele Demaria

### Ele Demaria (view profile)

Excellent tool! Thank you for sharing it.

Comment only
06 Apr 2016 Andre

### Andre (view profile)

That's correct. As Paul pointed out, the input vectors need to be rows. Thanks for the function and thanks Paul for the comment.

06 Apr 2016 Andre

31 Mar 2016 Paul

### Paul (view profile)

would be nice if it didn't freak out with column vectors. works well if i transpose my data vectors, but it took me a bit to figure that out. thanks!

19 Aug 2015 Francisco Hernandez

### Francisco Hernandez (view profile)

15 Feb 2015 nsc.clone

### nsc.clone (view profile)

I applied spline interpolation to fit the curve. In this case, how can I use 'jbfill' function to shade area between two curves.

For example:
x=[0 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300];
y=[0 28.23 27.3 20.94 13.89 6.268 2.468 0.1701 0.3704 0.1852 0.1852 0 0 0];
errBar=[0 3.366 4.936 4.969 2.294 2.353 1.568 0.1701 0.3704 0.1852 0.1852 0 0 0];

topcurve = y+errBar;
bottomcurve = y-errBar;

cs1=spapi(5,x,y);
fnplt(cs1);
hold on;
cs2=spapi(5,x,topcurve);
fnplt(cs2);
hold on;
cs3=spapi(5,x,bottomcurve);
fnplt(cs3);
hold on

Do you have a way to figure this out?

Comment only
10 Sep 2014 Alex Dytso

### Alex Dytso (view profile)

01 Aug 2014 Philippe

### Philippe (view profile)

Great!

19 May 2014 Logan

### Logan (view profile)

This only works with data input as rows. To allow for column or row vector input, add the following:
if iscolumn(xpoints)
xpoints = xpoints';
upper = upper';
lower = lower';
end

20 Mar 2014 Philip Ohnewein

### Philip Ohnewein (view profile)

26 Jul 2013 Markus Nenniger

### Markus Nenniger (view profile)

looks excellent, but somehow it doesnt save as pdf properly...

20 May 2013 Siddharth

### Siddharth (view profile)

I was using this program but unable to save my figure as jpeg/tif/bmp or copy this figure. This just give a black picture. I do not understand this have anyone came across this before?

07 May 2013 Stefano Gabriele

### Stefano Gabriele (view profile)

thanks, very very useful

23 Mar 2013 Enrico

### Enrico (view profile)

Very useful function. That really helped!

Thanks a lot!

08 Oct 2012 Allen

### Allen (view profile)

Great.

02 Oct 2012 Francesco Montorsi

### Francesco Montorsi (view profile)

I use this function for plotting confidence intervals... it's very useful, thanks!

10 Sep 2012 Lindsey

### Lindsey (view profile)

04 Feb 2012 Stephan

### Stephan (view profile)

16 Jan 2012 Vincent

### Vincent (view profile)

Works great, thanks!

03 Jan 2012 Timothy Kinyanjui

### Timothy Kinyanjui (view profile)

Great function

TERRIFIC! Thanks.

Comment only
04 Nov 2011 Clara

### Clara (view profile)

Easy to use, and very useful... at least for those of us working in geophysics. Thanks

28 Oct 2011 cehc84

### cehc84 (view profile)

29 Jun 2011 Brais

### Brais (view profile)

nice function, nice help, straightforward use

18 Feb 2011 Juan

### Juan (view profile)

great

23 Oct 2010 Jakob

### Jakob (view profile)

Simple and straight forward! Just what I needed.

30 Sep 2010 Ulrich Sachs

### Ulrich Sachs (view profile)

Very nice. But because of the transparancy, Matlab switches to OpenGL, which leads to vanishing axis. To avoid that I just make the axis lines thicker set(gca,'LineWidth',1.0).
Because logarithmic plots do not support OpenGL, you can not draw transparant areas in logarithmic plots.

16 Aug 2010 Grzegorz Knor

### Grzegorz Knor (view profile)

Very smart solution.

25 May 2010 Redmond

### Redmond (view profile)

This function is great, thanks very much. I was hoping to use it to highlight the time-periods for which there was a statistical difference between the two lines. After creating the basic plot, I created a new matrix which specifies the time-points of interest (statistcially significant) in the first column, and the relevant data points for the two lines in the 2nd and 3rd column. I then ran jbfill on this. Unfortunately because the periods of interest are non-contiguous the function fills in the area in between. Is there a way to make it so that it wil only shade in areas at the specific time-points I have specified?

21 Apr 2010 Robert Cumming

### Robert Cumming (view profile)

very good, and commented well (does what it says on the tin)

18 Nov 2009 SRG

### SRG (view profile)

04 Oct 2009 Matlaboscope

### Matlaboscope (view profile)

good but row vectors VS column vectors as input does matter.

10 Jun 2009 Andranik Valedi

### Andranik Valedi (view profile)

Beautiful.

07 Apr 2009 Ueli Rutishauser

### Ueli Rutishauser (view profile)

works great,thanks!
the "transparancy" option comes with a caveat: it will switch the renderer to opengl. After that, a vector export is not possible anymore (matlab limitation). set to 1.0 to avoid this problem.

06 Apr 2009 Ueli Rutishauser

### Ueli Rutishauser (view profile)

11 Feb 2009 ursula larke

### ursula larke (view profile)

thank you!!!! this came in REALLY handy! easy to use, well documented! :)

05 Sep 2008 Luis Concha

Very, very helpful and extremely easy to use. Great for confidence intervals!

06 Aug 2008 Yasser Soliman

Great. This was very helpful and saved me lots of time to figure out the exact work that you've done. Thanks!
On another note, I need a few vector-couples the area between which need to be shadded, on the same plot. How can I incorporate that?

26 May 2008 W. Johns

Good file, but the colour disappears when I switch to a vertical log scale. How can I fix this?

07 May 2008 Ta M

Thanks, exactly what I needed!
Also thanks to Chris: put data in row vectors!

13 Mar 2008 maka mohu

if you make I run the following example, matlab logs me off my user account on SuSe 10.2

for i=1:25
figure
% copy the jbfill.m example from the comments here.
close
end

Comment only
20 Feb 2008 W. H. Brave

Very good file, thank you.

06 Feb 2008 M H

lovely function but it is removing box around figure as consequence of transparency.

08 Dec 2007 Housam binous

Great job. Thanks for all.

02 Oct 2007 Luke Taylor

Just what I needed. Thanks!

31 Aug 2007 H W

Exactly what I needed. Thanks for posting!

01 Aug 2007 Marc Ferrer

Wonderful function.

13 Mar 2007 Matthias Brunner

Very nice. Thanks!

Works great, but apparently only when datapoint are horizontally organized (one row). If it's a column it doesn't work. You could mention this in the file.

11 Dec 2006 Francis Hossmeyer

Great! Solves a common problem.