Plot bar chart with log scale on y axis with different base
古いコメントを表示
I am ploting bar chart with log scale on y axis. I am using following code for log scale on y-axis.
set(gca,'YScale','log').
As default log scale base is 10 and I need to try different basis to fit my data.
please suggest how I can change log base for bar graph.
3 件のコメント
Rik
2020 年 9 月 20 日
The shape of your data won't change, as you just will be dividing by log10(new_base). You can modify the tick positions and labels if you insist, but it sounds like you want to fit some kind of function to your data, which shouldn't happen in the plot.
wasim hassan
2020 年 9 月 21 日
Rik
2020 年 9 月 21 日
Just make sure your baseline is below the lowest value, but above 0. That should make sure you can see all non-zero bars.
回答 (1 件)
Sindar
2020 年 9 月 20 日
% set whatever base you want (incl. decimals)
mybase = 2;
% get current limits
yl = ylim();
% convert to log-mybase scale
yt = reallog(yl) / log(mybase);
if any(isinf(yt))
error('don''t use log scale with zero limits')
end
% round outwards
yt(1) = floor(yt(1));
yt(2) = ceil(yt(2));
% set ticks to every power
% you may want to replace that '1' if too large of a range
% for bases less than 1, replace with '-1'
yts = yt(1):1:yt(2);
yticks(mybase.^yts);
% write the ticks in mybase^tick notation
yticklabels(compose('%g^{%d}',mybase,yts))
1 件のコメント
Sindar
2020 年 9 月 20 日
if the minor grid lines show up and annoy you as much as me:
set(gca,'YMinorGrid','off')
カテゴリ
ヘルプ センター および File Exchange で Bar Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
