Plot bar chart with log scale on y axis with different base

9 次查看(过去 30 天)
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 个评论
wasim hassan
wasim hassan 2020-9-21
Thank you for your reply. I have two 24x16 matrix. For each row of these matrixs, I am ploting 24 different bar graphs on one figure with same y-axis limit for all graphs. Some of entries of that matrix are very small as compared to others and bars of these small values are missing (as you can see in the figure some bars are not there although matrix entries are not zero at these locations). Actaully, using log scale on y-axis have improved non-zero number of visible bars but still some bars are missing. In short, I want to make all non-zero bars visible.
Rik
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
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))

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by