Log scale (x axis) histogram

戏子无情 提交于 2019-12-13 15:26:57

问题


what I need is a histogram with X axis displayed on a log scale. However, I still want every bar in a histogram to be of the same width.

Whatever, I came up with (or upon) display bars with higher values as narrower ones (they are of the same width on ordinary scale and not on log scale).

Here is what I am doing now:

edges = 10.^(c_min:0.1:c_max); 
h = histc(data, edges);
bar(edges, h); set(gca, 'Xscale', 'log');

回答1:


Since your bars should be evenly spaced, you can plot them with x-values 1,2,.. and then change the axis labels.

edges = 10.^(c_min:0.1:c_max); 
h = histc(data, edges);

centers = sqrt(edges(1:end-1).*edges(2:end));

bar(h)

%# fix the x-labels, x-axis extents
xlim([0.5,length(centers)+0.5])
set(gca,'xticklabel',num2str(centers(:),'%5.2f'))



回答2:


Use patch instead of bar:

figure, hold on
edges = 10.^(c_min:0.1:c_max);
h = histc(data, edges);

for ii = 1:numel(edges)-1    
    patch(...
        [edges(ii) edges(ii) edges(ii+1) edges(ii+1)], ...
        [0 h(ii) h(ii) 0],...
        'b');
end

Although this particular code does not do what you want, that is a problem with the definition of edges rather than the methodology, so you'd have to fiddle a bit with the edges (perhaps re-define them for the patch)



来源:https://stackoverflow.com/questions/11933787/log-scale-x-axis-histogram

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!