Main Content

xscale

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

Since R2023b

    Description

    xscale(scale) sets the scale of the x-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, xscale log is equivalent to xscale("log").

    example

    xscale(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

    xs = xscale returns the current x-axis scale value as 'linear' or 'log'.

    Examples

    collapse all

    Plot two vectors. Then display the axes grid.

    x = 1:10000;
    y = log10(x);
    plot(x,y)
    grid on

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

    Change the scale of the x-axis to be logarithmic.

    xscale 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:10000;
    y = log10(x);
    
    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 x-axis scale of the bottom plot to be logarithmic.

    xscale(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 XScale 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, xscale uses the current axes.

    Version History

    Introduced in R2023b

    See Also

    Functions

    Properties