# how to set y-axis as log scale?

7.003 visualizaciones (últimos 30 días)
Rohit Bhoi el 15 de Abr. de 2016
Editada: MathWorks Support Team el 22 de Sept. de 2023
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.
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Respuesta aceptada

Walter Roberson el 22 de Sept. de 2023
Editada: MathWorks Support Team el 22 de Sept. de 2023
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 comentariosMostrar 16 comentarios más antiguosOcultar 16 comentarios más antiguos
Weirong Sun el 9 de Mayo de 2022
good answer! It's very helpful!!!
mingyang zhao el 2 de Ag. de 2023
Great answer! Thank you!

Iniciar sesión para comentar.

### Más respuestas (2)

Rohit Sinha el 27 de Abr. de 2022
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 comentariosMostrar NingunoOcultar Ninguno
Walter Roberson el 27 de Abr. de 2022
semilogy() is the first thing I mentioned in my answer in 2016.
Nicholas Santiago el 4 de Nov. de 2022
yo i totally missed that I generally only read the bold stuff, thanks a ton!

Iniciar sesión para comentar.

Toshia M el 20 de Sept. de 2023
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
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Axis Labels en Help Center y File Exchange.

### Etiquetas

Aún no se han introducido etiquetas.

### Community Treasure Hunt

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

Start Hunting!

Translated by