# how to set y-axis as log scale?

6 461 views (last 30 days)
Rohit Bhoi on 15 Apr 2016
Commented: Walter Roberson on 13 Sep 2020
I am plotting x-y plot using plot function. I want to set only y-axis as log scale and x-axis as linear? How to do that? I used loglog function but it scales both axis but I want only Y.

Walter Roberson on 15 Apr 2016
Edited: MathWorks Support Team on 28 Nov 2018
The best way to create that type of axes is to use the semilogy function. Alternatively, you can set the ‘YScale’ property on the axes:
set(gca, 'YScale', 'log')

Walter Roberson on 30 Apr 2020
The log of negative real values is equal to the log of the positive value, plus (pi*1i) -- that is the result is complex. When you set YScale to log, then internally it would take the log of the negative values you have, and would found that the log is complex.
If, hypothetically, it were able to display with complex coordinates, where would you want the values displayed? For example do you want the complex portion of the coordinate to be treated as time, and the display should automatically cycle through a time period (perhaps every 2*pi seconds) with the negative values being displayed for one frame on each occasion that the complex value projected down to real?
If you want negative values to be displayed where the corresponding positive value would be displayed, then plot with abs(y) instead of y.
Remember, when you use log, there is an infinite distance in log scale between y = 1 and y = 0, since it has to pass through y = exp(-1), y = exp(-2), y = exp(-3), and so on, each of which needs to be allocated the same screen distance as between y = exp(0) and y = exp(1) . To get to negative y, you would have to go "further than infinity" down the bottom of the plot.
Brad Norton on 13 Sep 2020
what is gca?
Walter Roberson on 13 Sep 2020
ax = gca returns the current axes or chart for the current figure, which is typically the last one created or clicked with the mouse.

thank you , you help me too much

Hazem Mubarak on 30 Dec 2019
Thanks ;)