2014年5月22日星期四

Histograms of two sets of data with different color in matlab

Ref: http://chi3x10.wordpress.com/2008/03/10/histograms-of-two-set-of-data-with-different-color-in-matlab/
1
2
3
4
5
6
7
8
9
10
11
figure;
hist(data1);
hold on;
%//make data1 red
%//get the handle of the bars in a histogram
h = findobj(gca,'Type','patch');
%//color of the bar is red and the color of the border
%// of the bar is white!
set(h,'FaceColor','r','EdgeColor','w');
%//data 2 use default color!
hist(data2);
Edit: 03/30/09
As suggested by Adam in the comments, there is a better way to achieve that. Thanks Adam!!
_______________________________
The variable h contains handles to each of the histograms. Just use “set” on each element individually.
e.g.:
1
2
3
4
5
6
7
8
9
10
11
hist(data1);
 hold on;
 hist(data2);
 hist(data3);
 
h = findobj(gca,’Type’,’patch’);
display(h)
 
set(h(1),’FaceColor’,’r’,’EdgeColor’,’k’);
set(h(2),’FaceColor’,’g’,’EdgeColor’,’k’);
set(h(2),’FaceColor’,’b’,’EdgeColor’,’k’);

没有评论:

发表评论