Reputation:
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 they
-axis and a linear scale for thex
-axis. It plots the columns ofY
versus their index ifY
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);
But as we can see, the y-axis limits are different between the plots. Can anybody clear my doubt?
Upvotes: 3
Views: 4384
Reputation: 24169
When you use semilogy
you only change how the values are displayed, whereas if you manually perform the log
operation - you now have different values that you're plotting.
If we look into semilogy.m
we can see the following:
%SEMILOGY Semi-log scale plot. % SEMILOGY(...) is the same as PLOT(...), except a % logarithmic (base 10) scale is used for the Y-axis.
Thus, instead of using semilogy
you could get the same thing if you did:
plot(y1, 'linewidth', 2);
set(gca,'YScale','log');
Notice that the axes limits actually have the same meaning: in the right chart you get 0...2
and in the left you get 10^[0...2]
.
Upvotes: 3
Reputation: 3106
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.
Upvotes: 4