# how to set y-axis as log scale?

6,719 ビュー (過去 30 日間)
Rohit Bhoi 2016 年 4 月 15 日
コメント済み: Walter Roberson 2020 年 9 月 13 日
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 2016 年 4 月 15 日

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')

#### 9 件のコメント

Walter Roberson 2020 年 4 月 30 日
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 2020 年 9 月 13 日
what is gca?
Walter Roberson 2020 年 9 月 13 日
ax = gca returns the current axes or chart for the current figure, which is typically the last one created or clicked with the mouse.

サインインしてコメントする。

### その他の回答 (2 件)

Elkin Javier Cepeda Ramirez 2019 年 5 月 3 日
thank you , you help me too much

#### 0 件のコメント

サインインしてコメントする。

Hazem Mubarak 2019 年 12 月 30 日
Thanks ;)

サインインしてコメントする。

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by