Main Content

zscale

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

Since R2023b

    Description

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

    example

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

    zs = zscale returns the current z-axis scale value as 'linear' or 'log'.

    Examples

    collapse all

    Create matrices X, Y, and Z, and use them to create a surface plot.

    [X,Y] = meshgrid(0:1:100);
    Z = X.*Y;
    surf(X,Y,Z,EdgeColor="none")
    view(-145,10)

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

    Change the scale of the z-axis to logarithmic.

    zscale log

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

    Create the same surface 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,Y] = meshgrid(0:1:100);
    Z = X.*Y;
    
    nexttile;
    surf(X,Y,Z,EdgeColor="none")
    view(-145,10)
    title("Linear Scale")
    
    ax2 = nexttile;
    surf(X,Y,Z,EdgeColor="none")
    view(-145,10)
    title("Log Scale")

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

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

    zscale(ax2,"log")

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

    Input Arguments

    collapse all

    Scale value, specified as "linear" or "log". When you change the scale, MATLAB® changes the ZScale 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, zscale uses the current axes.

    Version History

    Introduced in R2023b

    See Also

    Functions

    Properties