如何使用对数刻度绘制hist

时间:2011-07-25 07:27:21

标签: matlab

x = [1: 1000]
hist(x)

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

4 个答案:

答案 0 :(得分:7)

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

答案 1 :(得分:3)

我建议使用带有对数边和条形图的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)

答案 2 :(得分:3)

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

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

但是这篇文章也解释了几个工作场所。

答案 3 :(得分:0)

尝试:

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');
相关问题