Code covered by the BSD License  

Highlights from
bihist (back to back histogram)

5.0

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

bihist (back to back histogram)

by Mauro

 

17 Mar 2009 (Updated 18 Sep 2009)

create a back-to-back histogram

| Watch this File

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)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
18 Mar 2009 Mauro

new version is on the way

09 Sep 2009 Anastasia

%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.
%Hope it's a useful addition.

% 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

07 Oct 2009 Mauro

Thx, i hope you like the new version

Please login to add a comment or rating.
Updates
18 Mar 2009

change in labeling the y-axis

18 Sep 2009

new colour and new label for x-axis

Tag Activity for this File
Tag Applied By Date/Time
statistics Mauro 17 Mar 2009 15:17:49
back Mauro 17 Mar 2009 15:17:49
back to back Mauro 17 Mar 2009 15:17:49
bihistogram Mauro 17 Mar 2009 15:17:49
histogram Mauro 17 Mar 2009 15:17:49
hist Mauro 17 Mar 2009 15:17:49
bihist Mauro 07 Oct 2009 04:02:57

Contact us at files@mathworks.com