【问题标题】:How to plot hist with log scale如何用对数刻度绘制 hist
【发布时间】:2011-07-25 07:27:21
【问题描述】:
x = [1: 1000]
hist(x)

然后,有图显示直方图,但如果我将轴属性和 Y 轴设置为日志。我在图中看不到任何东西。如何用对数刻度绘制直方图。

【问题讨论】:

    标签: matlab


    【解决方案1】:

    尝试set(gca, 'Xscale', 'log') 在 X 轴上绘制日志。它对我有用,我使用的是 7.12.0 或 2011a。更多帮助请查看axis reference

    【讨论】:

      【解决方案2】:

      我建议将 histc 与日志边缘和条形图一起使用

      help histc
      -- Function File: N = histc (Y, EDGES)
      
      matlab> edges=log(1:100:1000); 
      matlab> h=histc(x,edges)
      matlab> bar(1:100:1000, h)
      

      【讨论】:

      • 您必须在 bar 中添加 'histc' 选项以保持 histc 边缘功能:bar(1:100:1000, h, 'histc')
      【解决方案3】:

      据我所知,它不能作为原生 matlab 函数使用:

      http://www.mathworks.com/support/solutions/en/data/1-2ZUTKK/?solution=1-2ZUTKK

      但是这篇文章也解释了几个解决方法。

      【讨论】:

        【解决方案4】:

        试试:

        function semilogxhist(val,M)
        % semilogxhist - generate histogram with M bars and log-scale x axis
        if nargin<2; M=min(30,sqrt(length(val))); end
        vmin=min(val); vmax=max(val);
        edges=vmin*(vmax/vmin).^([0:M]/M);
        count=histc(val,edges); 
        if size(count,2)==1, count=count'; end 
        x=edges(sort([1:M 1:M])); 
        y=[0 count(sort([1:M-1 1:M-1])) 0];
        % outline only: semilogx(x, y, '-');
        plot(x, y, '-'); fill(x, y, 'b'); set(gca,'XScale','log');
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-09-15
          • 2017-09-08
          • 2020-11-19
          • 1970-01-01
          • 1970-01-01
          • 2018-07-26
          相关资源
          最近更新 更多