【问题标题】:MATLAB - Can you do a multiple histogram figure?MATLAB - 你能做一个多重直方图吗?
【发布时间】:2011-03-04 22:05:06
【问题描述】:

我想在一个图中绘制多个直方图,就像 subplot 命令一样,只使用直方图。有没有办法在 MATLAB 中做到这一点?

【问题讨论】:

    标签: matlab histogram


    【解决方案1】:

    在不同的子情节中?

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

    【讨论】:

      【解决方案2】:

      可以使用 hold on 将多个直方图放在一个图中。但是,您需要在绘制下一个直方图之前更改第一个直方图的颜色。

      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)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-02-13
        • 1970-01-01
        • 2014-06-19
        • 2017-06-09
        • 1970-01-01
        • 1970-01-01
        • 2019-04-20
        • 2015-09-21
        相关资源
        最近更新 更多