how to set y-axis as log scale?

조회 수: 6,953 (최근 30일)
Rohit Bhoi
Rohit Bhoi 2016년 4월 15일
편집: MathWorks Support Team 2023년 9월 22일
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
Walter Roberson 2023년 9월 22일
편집: MathWorks Support Team 2023년 9월 22일
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')
***Update from Mathworks Support Team - September 2023***
As of R2023b, you can also use the 'yscale ' function. 
  댓글 수: 18
Weirong Sun
Weirong Sun 2022년 5월 9일
good answer! It's very helpful!!!
mingyang zhao
mingyang zhao 2023년 8월 2일
Great answer! Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Rohit Sinha
Rohit Sinha 2022년 4월 27일
The easiest way to do this is simply use the following command instead of plot
semilogy(x,y);
This will plot x axis on a linear scale and y axis on a log scale. Similarly, if you want to plot x axis on log scale and y axis on a linear scale, you can use
semilogx(x,y) ;
  댓글 수: 2
Walter Roberson
Walter Roberson 2022년 4월 27일
semilogy() is the first thing I mentioned in my answer in 2016.
Nicholas Santiago
Nicholas Santiago 2022년 11월 4일
yo i totally missed that I generally only read the bold stuff, thanks a ton!

댓글을 달려면 로그인하십시오.


Toshia M
Toshia M 2023년 9월 20일
Starting in R2023b, you can change the scale of any axis after you create the plot by calling the xscale, yscale, or zscale function.
For example, create a plot of two vectors x and y. Then set the scale of the y-axis to logarithmic.
x = 1:100;
y = x.^2;
plot(x,y)
grid on
yscale log

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by