Base-2 logarithmic scale on bar diagram

14 views (last 30 days)
D12
D12 on 16 Nov 2022
Commented: dpb on 16 Nov 2022
Hello,
I would like to plot a bar diagram but with a base-2 logarithmic scale on y-axis. Is it possible to have a logarithmic scale with the bar function ? Can someone help me ?
Here is an example of a diagram with a linear scale on which I would like to use a base-2 logarithmic scale on y-axis
figure;
set(gcf,'color','w');
x=[1 2 3 4];
y= [3 0.76 .82
4.2 1.1 0.9
2.5 0.75 0.85
0.8 0.9 3.5];
b= bar (x,y,1);
  1 Comment
dpb
dpb on 16 Nov 2022
What, specifically, is the expected result to look like? Since
log2(y)=log10(y)/log10(2)
by definition, it's a linear scaling so just using
...
hB=bar(x,y,1);
hAx=gca; hAx.YScale='log';
will produce the same relative bar heights as those if you were to mess around with the log2() values and scale them.

Sign in to comment.

Accepted Answer

David Hill
David Hill on 16 Nov 2022
A logarithmic scale does not matter what the base is. You can change the markers to whatever you want (powers of two).
figure;
set(gcf,'color','w');
x=[1 2 3 4];
y= [3 0.76 .82
4.2 1.1 0.9
2.5 0.75 0.85
0.8 0.9 3.5];
b= bar (x,y,1);
set(gca, 'YScale', 'log')

More Answers (0)

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!