Code covered by the BSD License  

Highlights from
boundedline: line plots with shaded error/confidence intervals

4.6

4.6 | 11 ratings Rate this file 172 Downloads (last 30 days) File Size: 4.7 KB File ID: #27485
image thumbnail

boundedline: line plots with shaded error/confidence intervals

by Kelly Kearney

 

05 May 2010 (Updated 30 Jan 2013)

Plot one or more lines with a shaded boundary (can represent error, confidence intervals, etc).

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information
Description

This function allows you to plot one or more lines with their error range/confidence intervals/whatever bounds you require. It provides an advantage over several other similar entries on the FEX in that it:

1) allows x-y input similar to plot, where one call can create multiple lines at once, either by listing consecutive x-y pairs or by using using matrices for x and/or y.

2) can add bounds in either the x- or y-direction, leading to support of plots where the x axis represents the dependent variable

3) can render the shaded bounds either with transparency or as a lighter opaque patch, allowing flexibility with different renderers (helpful when OpenGL acts up, as it often does on my own computer).

4) Can use linespec definitions, a colormap, or the default color order, as well as varying color intensity for the shaded bounds, for flexible color of lines and bounds

5) returns handles of lines and patches for future modification if necessary

Acknowledgements

Confplot, Errorfill, and Shaded Error Bar inspired this file.

MATLAB release MATLAB 7.5 (R2007b)
Tags for This File  
Everyone's Tags
bounds line confidence interval errorbar shaded(2), pick of the week, potw, so well programmed(2)
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (15)
02 Apr 2013 Warwick  
28 Feb 2013 Daniel Lopes

Works like a charm! Great code.

17 Feb 2013 Kelly Kearney

@Gideon and Martin,

There's nothing in this function preventing you from setting the axis to a log scale via 'xscale' and 'yscale' properties, assuming all your inputs lead to positive values for the boundaries (like NaNs and Infs, negative values displayed on a log scale will cause the bounds patch to disappear). If you are looking for something more complex than that, please send me an example and I'll look into it.

15 Feb 2013 Martin Nors Pedersen

Great function - very useful

like Gideon Simpson i would to plot some of my data on log scale - is this possible using this function?

when i try the bounderies are same color as the line so it is difficult to distinquish what is the mean and what is the stdev :)

20 May 2012 Gideon simpson

Works well, but is it possible to put one of the axes on a log scale?

30 Jan 2012 Mohammed Alwesabi  
07 Oct 2011 dbgtjp

excellent work.
if anybody else wants to avoid the patches appear in the legend simply add the following code after line 314.

set(get(get(hp(iln),'Annotation'),'LegendInformation'),'IconDisplayStyle','off');

this does the trick.

07 Oct 2011 dbgtjp  
26 Aug 2011 Vassilis Kehayas  
26 Mar 2011 Felipe G. Nievinski

good job in pointing out advantages over several other similar entries on the FEX.

06 Jan 2011 Il

Awesome. It works perfectly on the screen.
The only problem for me is that the transparent color cannot be exported with vector graphics pdf. If opengl renderer is used, it will convert it to raster, which is not so desirable.

11 Aug 2010 Alexander  
10 Aug 2010 Alexander

I experienced the following problem on my mashine with nVidia graphics:
When using the 'alpha' option the axes are overlayed. This a problem caused by the OpenGL rendering.
Workaround: activate software rendering by
opengl software;

09 Jun 2010 Dylan

This is a very useful function that does almost exactly what I was trying to do, and it should save me a lot of time. Thanks for making it!

I think, though, that it would be even more useful if you made two modifications:

1) The reference color of the bounded area should be set independently (as an RGB array), rather than being constrained to be a lighter shade of the corresponding line color. This would be particularly relevant for users preparing b&w figures for publication who, for example, might want to use two black lines and two different shades of grey for the bounded areas. The specific example I provided could of course be facilitated simply by allowing separate transparency parameters for each bounded area, but that still would not provide as much flexibility as some users might want.

2) The default behavior of 'legend' is to use shaded boxes that are the same colors as the bounded areas. Some users might prefer that the legend use lines of the same color and style as the corresponding data. It would be nice to have the option of using either. I believe this could be controlled from within boundedline.m by setting the 'IconDisplayStyle ' property of the 'LegendEntry' array of each patch to 'on' or 'off'.

Example code:
set(get(get(hPatches(1),'Annotation'),'LegendInformation'),'IconDisplayStyle','off')

Also, there appears to be a bug (using R2007b): adding a legend to a figure that was made using the 'alpha' option results in no legend and no bounded areas.

19 May 2010 Zachary Danziger

Nice file. I enjoy the flexibility.

Updates
30 Jan 2013

Added outlinebounds.m function to allow outlining of patch objects (can be useful to see overlap when using opaque bounds).

Contact us