%
1;

% apply a improved axes ticks
function fix_axes_ticks (hax, s_axis, tick_density)
  if ~exist ('tick_density', 'var') || isempty (tick_density)
    tick_density = 3;
  end
  yb = ylim (hax);
  scaling_mode = strcmp (get (hax, [s_axis 'scale']), 'log');

  [ticks_major, ticks_minor] =...
    calc_axis_ticks (yb(1), yb(2), tick_density, scaling_mode);

  set (hax, [s_axis 'tick'], ticks_major)
  set (hax, [s_axis 'minortickvalues'], ticks_minor)
end

% Large scale range
figure(11)
semilogy (logspace (-50, 1, 100))
fix_axes_ticks (gca, 'y');

% small scale range
figure(12)
semilogy (logspace (3, 3.7, 100))
fix_axes_ticks (gca, 'y');

% tiny scaling range, typically happens when zoom in.
figure(13)
semilogy (linspace (1, 1.01, 100))   % zoom in

% get ylim from 'auto' mode linear ylim.
set (gca, 'yscale', 'linear');
yb = ylim(gca);
set (gca, 'yscale', 'log');
ylim(yb);
fix_axes_ticks (gca, 'y');

% fix also labels when suitable (e.g. y is O(1))
ytk = get (gca, 'ytick');
st_ytk = arrayfun(@(x)sprintf("%g",x), ytk, "UniformOutput", false);
set(gca, 'yticklabel', st_ytk)

%get(gca, 'yminortick')  % 'on', 'off'
