Main Content

yscale

Set or query y-axis scale (linear or logarithmic)

Since R2023b

    Description

    yscale(scale) sets the scale of the y-axis to be linear or logarithmic in the current axes. Specify scale as "linear" or "log". You can also omit the parentheses and quotation marks when using this syntax. For example, yscale log is equivalent to yscale("log").

    example

    yscale(ax,___) sets the scale for the specified axes object. This syntax is useful when you are working with multiple plots, either in a tiled chart layout or in different figures.

    example

    ys = yscale returns the current y-axis scale value as 'linear' or 'log'.

    Examples

    collapse all

    Create vectors x and y and plot them. Then display the axes grid.

    x = 1:100;
    y = x.^2;
    plot(x,y)
    grid on

    Figure contains an axes object. The axes object contains an object of type line.

    Change the scale of the y-axis to logarithmic.

    yscale log

    Figure contains an axes object. The axes object contains an object of type line.

    Create the same line plot twice in a tiled chart layout. This code calls the nexttile function to create a tiled chart layout with one axes object. The second call to nexttile creates and returns the second axes object.

    x = 1:100;
    y = x.^2;
    
    nexttile;
    plot(x,y)
    grid on
    title("Linear Scale")
    
    ax2 = nexttile;
    plot(x,y)
    grid on
    title("Log Scale")

    Figure contains 2 axes objects. Axes object 1 with title Linear Scale contains an object of type line. Axes object 2 with title Log Scale contains an object of type line.

    Change the y-axis scale of the bottom plot to logarithmic.

    yscale(ax2,"log")

    Figure contains 2 axes objects. Axes object 1 with title Linear Scale contains an object of type line. Axes object 2 with title Log Scale contains an object of type line.

    Input Arguments

    collapse all

    Scale value, specified as "linear" or "log". When you change the scale, MATLAB® changes the YScale property of the axes object to the value you specify.

    Note

    When you specify a logarithmic scale, the axes might exclude coordinates in some cases:

    • If the coordinates include positive and negative values, only the positive values are displayed.

    • If the coordinates are all negative, all of the values are displayed on a logarithmic scale with the appropriate sign.

    • Zero values are not displayed.

    Target Axes object. If you do not specify the target axes, yscale uses the current axes.

    Version History

    Introduced in R2023b

    See Also

    Functions

    Properties