File Exchange

image thumbnail

Shaded area error bar plot

Error bar plot with filled area curves.

117 Downloads

Updated 09 Oct 2018

View License

This function plots the mean and standard deviation of a set of data filling the space between the positive and negative mean error using a semi-transparent background, completely customizable.

Input parameters:
- data: Data matrix, with rows corresponding to observations and columns to samples.
- options: (Optional) Struct that contains the customized params.
* options.handle: Figure handle to plot the result.
* options.color_area: RGB color of the filled area.
* options.color_line: RGB color of the mean line.
* options.alpha: Alpha value for transparency.
* options.line_width: Mean line width.
* options.x_axis: X time vector.
* options.error: Type of error to plot.
if 'std', one standard deviation;
if 'sem', standard error mean;
if 'var', one variance;
if 'c95', 95% confidence interval.
Example of use:
data = repmat(sin(1:0.01:2*pi),100,1);
data = data + randn(size(data));
plot_areaerrorbar(data);

Cite As

Víctor Martínez-Cagigal (2020). Shaded area error bar plot (https://www.mathworks.com/matlabcentral/fileexchange/58262-shaded-area-error-bar-plot), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (13)

it is a good function, but that would be great if you include an example that how can we use an x-axis different from the length of data.

Great function! I just have a suggestion: if you want to define the x data using options.x_data, you must also include all the other options fields (e.g. options.handle, options.color_area...), otherwise it gives an error. It happens the same with all the other options' fields If you add something similar to what you do for options.x_axis, you solve this problem. You can add for example:

if ~isfield(options,'handle'); options.handle=figure(1);end
if ~isfield(options,'color_area'); options.color_area = [128 193 219]./255; end
if ~isfield(options,'color_line'); options.color_line = [ 52 148 186]./255; end
if ~isfield(options,'alpha'); options.alpha = 0.5; end
if ~isfield(options,'line_width'); options.line_width = 2; end
if ~isfield(options,'error'); options.error = 'std'; end

Nice idea!

Excellent

@Ahmad I just tested it and it works:

data = repmat(sin(1:0.01:2*pi),100,1);
data = data + randn(size(data));
plot_areaerrorbar(data);
data = repmat(sin(1.5:0.01:2*pi),100,1);
data = data + randn(size(data));
hold on
plot_areaerrorbar(data);

Hi!

This works well for one data set, but when i use hold on, only the second data set is plotted, not sure why?

Anoop B J

Hi,

I am having a problem with setting the x axis right. Other things seem to work fine. But the x axis is only drawn between 1 and 2. Could you help out with that please?

Below is the data I am working with. I want to plot a scatterplot with shaded confidence intervals.

a = [146.146 154.006
144.498 148.602
117.563 145.987
108.53 113.418
109.366 119.78
128.15 132
115.02 120.584
122.88 125.69
140.109 150.013
99.347 100.333
112.768 113.58
104.246 114.114
];

When I try
plot_areaerrorbar(a), the x axis is between 1 and 2. I am not able to understand how to make the plot to be the same length as my data.

Rob Campbell

Might be neater with an input parser instead of the structure for the optional arguments: https://ch.mathworks.com/help/matlab/ref/inputparser.addparameter.html

Javier

Javier

Thank you. Excellent function.

Updates

1.3.1

Name

1.3

Due to changes in std() function, now calculates the proper standard deviation across observations.

1.2.0.0

Title is modified.

1.1.0.0

Now the function displays one standard deviation up and one down.

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