MATLAB: Is the layout of the axes not nicely chosen when I use SEMILOGX, SEMILOGY or LOGLOG for plotting

MATLAB

The following example shows what I mean:
x = [0.025 0.05 0.1];
y = [0.0264 0.0423 0.0674];
loglog(x,y)
The y-axis is chosen with fractional powers of 10, which is good. The x-axis, however, only shows 10^(-1) as a major tick with minor ticks at the integer multiples of 10^(-2). I would like to have either fractional powers of 10^(-1) on the x-axis too or at least the axis to show 10^(-2) as well, so that it becomes more clear from the plot what those minor ticks actually stand for.

Best Answer

This is caused by the way that the plot commands that work with a logarithmic scale choose the axis limits, when the lower or upper limit in the data points is an exact power of 10. In the example, the upper bound on the x-data is 0.1, which is 10^(-1), i.e. an integer power of 10.
To work around this, you can choose either to subtract or add eps from the data point that is causing the weird choice of axis limits before plotting. In the case where you subtract eps it will recognize that it is not passing an integer multiple and will switch to fractional powers of 10:
x = [0.025 0.05 0.1];
y = [0.0264 0.0423 0.0674];
x(3) = x(3) - eps;
loglog(x,y)
In the case where you add eps it will recognize that it is crossing an integer power of 10 and it will extend the axis to stretch from 10^(-2) to 10^0, placing minor ticks at integer multiples of integer powers of 10:
x = [0.025 0.05 0.1];
y = [0.0264 0.0423 0.0674];
x(3) = x(3) + eps;
loglog(x,y)