2011-03-04 43 views

回答

3

在不同的子圖?

subplot(2,1,1) 
hist(...) 
subplot(2,1,2) 
hist(...) 
0

可以使用保持將多個直方圖放在一個圖中。但是,在繪製下一個直方圖之前,您需要更改第一個直方圖的顏色。

x1 = randn(1000,1);x2 = 1 + randn(1000,1); 
hist(x1,100), hold on 
h = findobj(gca,'Type','patch'); 
set(h,'FaceColor','r','Edgecolor','c') 
hist(x2,100) 

儘管比較直方圖時應該小心,因爲直方圖箱是單獨生成的。

我用下面的補充解決此問題:

x1 = randn(1000,1);x2 = 1 + randn(1000,1); 
xrangel = min(min(x1),min(x2)); 
xrangeh = max(max(x1),max(x2)); 
x1_tmp = x1(x1>=xrangel & x1<=xrangeh); 
x2_tmp = x2(x2>=xrangel & x2<=xrangeh); 
xbins = xrangel:(xrangeh - xrangel)/res:xrangeh; 
hist(x1_tmp,xbins) 
hold on 
h = findobj(gca,'Type','patch'); 
% some additional coloring to help visibility 
set(h,'FaceColor','c','EdgeColor',[0 0.99 0],'LineWidth',1.2,'LineStyle','-','EdgeAlpha',0.89); 
hist(x2_tmp,xbins)