set width of bars in matlab bar plot on logarithmic scale

Posted by KatyB on Stack Overflow See other posts from Stack Overflow or by KatyB
Published on 2014-06-13T09:21:01Z Indexed on 2014/06/13 9:24 UTC
Read the original article Hit count: 188

Filed under:

I am a bit confused on how to draw a bar graph for the following example:

x_lims = [1000,10000;10000,100000;100000,1000000;1000000,10000000;10000000,...
    100000000;100000000,1000000000;1000000000,10000000000;...
    10000000000,100000000000;100000000000,1e12]; 
ex1 = [277422033.049038;24118536.4203188;2096819.03295482;...
    182293.402068030;15905;1330;105;16;1];

Here, x_lims is the x axis limits for each individual bar and ex1 is the count. How can I plot these on a bar graph so that the width of each individual bar along the x axis is defined by the distance between x_lims(:,1) and x_lims(:,2) and the y value is defined by ex1?

So far I have:

bar(log10(x_lims(:,1)),log10(ex1));
set(gca,'Xtick',3:11,'YTick',0:9);
set(gca,'Xticklabel',10.^get(gca,'Xtick'),...
    'Yticklabel',10.^get(gca,'Ytick'));

enter image description here

But I would like to (1) have the labels to be the same as if they were created using semilogx or semilogy e.g. 10^9, and (2) I would like to remove the space between the bars, for the first bar, for example, I would like to have it extend horizontally from 1000 to 10000 and then the second bar from 10000 to 100000, and so on. How can this be done?

© Stack Overflow or respective owner

Related posts about matlab