File Exchange

image thumbnail


version (532 KB) by Chad Greene
A nuanced method of plotting uncertainty.


Updated 27 Jul 2016

View Version History

View License

It's common to use a shaded region or error bars to depict uncertainty in plots. However, shaded regions and error bars tend to have definite extents, which rarely represents the reality of uncertainty. In truth, gaussian uncertainty tapers gradually, and should be depicted accordingly.

Too often we try to depict a binary world in which all values are either within the range of uncertainty, or outside the range of uncertainty. This function is meant to show that all errors are *not* contained within the arbitrary bounds of one standard deviation of the noise. To accomplish this, the errorshade function creates a semitransparent RGB image of a specified color, whose opacity scales directly with a gaussian distribution of uncertainty.

Cite As

Chad Greene (2021). errorshade (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (6)

Oleg Komarov

I think the image should be updated. The function works well now, but the snapshot is a bit off.

Chad Greene

Oleg--Thanks for pressing this issue. I took a closer look and found I'd left out a ^2 in the calculation of the Gaussian distribution. The error has been fixed.

Oleg Komarov

Uncertainty should go both ways independent of what is the direction of the step, but here it looks like if the increment is positive, we have only positive uncertainty, although a two-tailed normal assumption should give confidence intervals on both ends.

Chad Greene

Oleg--Indeed, the spikes look weird, but it's an accurate depiction of the underlying assumption that each measurement is independent and uncertainty at each measurement is not a function of neighboring measurements.

If your application permits violating that assumption and you want a prettier plot, consider calling errorshade with a moving average. In the example provided the moving-average implementation might look like this:

errorshade(x,imfilter(y_measured,fspecial('average',[1 5]),'replicate'),sigma,[0.0824 0.6902 0.1020])

Oleg Komarov

Isn't the blurring a bit weird with those triangular spikes alternative up and down? I would expect a more uniform blurring.

Ben Dichter

very cool! Would be really useful for teaching stats!

MATLAB Release Compatibility
Created with R2012b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!