Code covered by the BSD License

Highlights from bihist (back to back histogram)

5.0
5.0 | 1 rating Rate this file 11 Downloads (last 30 days) File Size: 1.68 KB File ID: #23312

bihist (back to back histogram)

by

Mauro (view profile)

17 Mar 2009 (Updated )

create a back-to-back histogram

File Information
Description

a good way to show differences between two sets of data about their location and distribution

MATLAB release MATLAB 7.8 (R2009a)
07 Oct 2009 Mauro

Mauro (view profile)

Thx, i hope you like the new version

Comment only
09 Sep 2009 Anastasia

Anastasia (view profile)

%Just edited this one a bit to have more consistency in setting %colours and to keep the variable names a bit more clear %(left/right).
%Also, I put the scale back in and the histograms are now on the %same scale, although it shows a negative value on the left at %the moment.

% BIHIST(X1,X2,N) open a new figure an plot a back to back histogram
% X1: variable 1 (right side, colour blue)
% X2: variable 2 (right side, colour green)
% n : number of classes for each histogramm

% make two dummy-histogram
[temp, d1] = hist(x1,n);
[temp, d2] = hist(x2,n);
clear temp
% calculate classes
d = min([d1 d2]):((max([d1 d2])-min([d1 d2]))/(n-1)) : max([d1 d2]);
% create the two histograms
templ = hist(x1,d);
tempr = hist(x2,d);
% scaling the histograms
%temp1 = temp1/sum(temp1);
%temp2 = temp2/sum(temp2)*-1;
templ=templ*-1
% create bar plot
left=barh(templ,'style','hist')
hold on
right = barh(tempr,'style','hist');
plot([0 0], [1 n],'k')
% change color of left histogram
set(left,'FaceColor',[0 0 1]);
% change color of right histogram
set(right,'FaceColor',[0 1 0]);
%clear the x-axis
%set(gca,'XTick',0)
%set(gca,'XTickLabel',{''})
dt=1.2;
xlim([-max(abs([templ tempr]))*dt max(abs([templ tempr]))*dt])
% mark the y-axis
yl = get(gca,'YTick');
b = (max(d)-min(d))/(n-1);
a = max(d)-b*n;
yl2 = yl*b+a;
ds = cell(size(yl2));
for k=1:length(yl2)
ds{k} = num2str(yl2(k),3);
end
set(gca,'YTickLabel',ds)
clear k

18 Mar 2009 Mauro

Mauro (view profile)

new version is on the way

Comment only