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

22 Ansichten (letzte 30 Tage)
wasim hassan
wasim hassan am 20 Sep. 2020
Kommentiert: Rik am 21 Sep. 2020
I am ploting bar chart with log scale on y axis. I am using following code for log scale on y-axis.
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 Kommentare
Rik am 21 Sep. 2020
Just make sure your baseline is below the lowest value, but above 0. That should make sure you can see all non-zero bars.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Sindar am 20 Sep. 2020
% 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')
% 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);
% write the ticks in mybase^tick notation
  1 Kommentar
Sindar am 20 Sep. 2020
if the minor grid lines show up and annoy you as much as me:

Melden Sie sich an, um zu kommentieren.


Find more on 2-D and 3-D Plots in Help Center and File Exchange


Community Treasure Hunt

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

Start Hunting!

Translated by