2011-03-04 48 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)