Search code examples
matlabplotmatlab-figureaxeslogarithm

Understanding semilogy function


I'm trying to understand semilogy function which is normally used for plotting data in MATLAB.

As the definition says in MATLAB help section:

semilogy(Y) creates a plot using a base 10 logarithmic scale for the y-axis and a linear scale for the x-axis. It plots the columns of Y versus their index if Y contains real numbers.

The below code should produce same plot:

y1 = 1:100;
figure
semilogy(y1, 'linewidth', 2);

x2 = 1:100;
y2 = log10(x2);
figure
plot(x2, y2, 'linewidth', 2);

enter image description here

But as we can see, the y-axis limits are different between the plots. Can anybody clear my doubt?


Solution

  • In the first one the axes are setup to perform the logarithm and pretty print the ticklabels and grids automatically. Hence the numbers are still in their absolute value. But their markings are according to the logarithmic axis. In the second one you are just plotting log function with a linear axis. Though looks similar they are not the same plots.

    Maybe turning the grid on can give you the idea better about it. Have a look at where 8 or 80 is in both plots.

    enter image description here