How do I make shaded error bar area instead of lines?

128 views (last 30 days)
I have data as a neuronal response function listed as my first line of code which is the curve I get. I am trying to add shaded error bars that look similar to this:
My code is:
load('0_RF_PSD95-3_20111121-3.CNG.swc_Trials_120_length_2000_p_0.995_a_0.8_beta_0.6.mat')
SDdiff = std(diff(sort(Fsoma)));
figure; errorbar(h(2:end), diff(mean(Fsoma/500)), ...
SDdiff(2:end)/500);
set(gca, 'XScale', 'log')
and my current figure/output is:
Does anyone know how to help me achieve something similar to the first figure? Thank you in advance.
  2 Comments
Dyuman Joshi
Dyuman Joshi on 30 Aug 2023
One way to achieve this to have more number of data points for a range (to make it dense) and remove the error bar cap
x1 = 0:0.1:10;
numel(x1)
ans = 101
curves(x1)
x2 = 0:0.01:10;
numel(x2)
ans = 1001
curves(x2)
function curves(x)
figure
y = sin(x);
err = 0.1*abs(y)+0.1;
e = errorbar(x,y,err);
%Change the cap size to 0 to remove the cap on error bars
e.CapSize = 0;
hold on
%Add the original plot
plot(x,y,'k-');
end
Adam Danz
Adam Danz on 30 Aug 2023
There's a well-supported function on the File Exchange that adds shaded error regions.

Sign in to comment.

Answers (1)

Star Strider
Star Strider on 30 Aug 2023
It would help to have your data.
Perhaps something like this —
x = logspace(-10, 5, 150).'; % Assume Column Variables
y = sin(2*pi*x/1E4)*0.1 + 0.5;
err = 0.01+rand(size(x))*0.05;
figure
errorbar(x, y, err)
set(gca, 'XScale', 'log')
figure
plot(x, y)
hold on
patch([x; flip(x)], [y-err; flip(y+err)], 'b', 'FaceAlpha',0.25, 'EdgeColor','none')
hold off
set(gca, 'XScale', 'log')
.
  6 Comments

Sign in to comment.

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!