Created
September 1, 2015 14:45
-
-
Save williamrowell/e6d67298f0b983cd06d2 to your computer and use it in GitHub Desktop.
scatter plots with error bars and jitter in MATLAB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function error_jitter(xvals, yvals, errvals) | |
%%ERROR_JITTER(xvals, yvals) | |
% | |
% xvals -> array of x positions | |
% yvals -> cell array of multiple y positions for each x position | |
% errvals -> cell array of multiple std/sem for each x position | |
% TODO: allow yvals/errvals to be ragged array | |
% | |
% author: William Rowell ([email protected]) | |
hold on | |
for xidx = 1:length(xvals) | |
% spread data over region from x-0.2 to x+0.2 | |
num_yvals = length(yvals{xidx}); | |
jitter_delta = 0.4 / num_yvals; | |
x = repmat(xvals(xidx),[num_yvals, 1]); | |
jitter = ((0:(num_yvals-1))*jitter_delta - 0.2); | |
x = x + jitter'; | |
y = yvals{xidx}; | |
err = errvals{xidx}; | |
errorbar(x,y,err,'bo'); | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment