主要内容

xscale

设置或查询 x 轴刻度(线性或对数)

自 R2023b 起

    说明

    xscale(scale)x 轴的刻度设置为当前坐标区中的线性或对数刻度。将 scale 指定为 "linear""log"。使用此语法时,也可以省略括号和引号。例如,xscale log 等同于 xscale("log")

    示例

    xscale(ax,___) 设置指定坐标区对象的刻度。当您在分块图布局或不同图窗中处理多个图时,此语法非常有用。

    示例

    xs = xscale'linear''log' 形式返回当前 x 轴刻度值。

    示例

    全部折叠

    绘制两个向量。然后显示坐标区网格。

    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.

    x 轴的刻度改为对数刻度。

    xscale log

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

    在一个分块图布局中两次创建相同的线图。以下代码调用 nexttile 函数来创建具有一个坐标区对象的分块图布局。对 nexttile 的第二次调用会创建并返回第二个坐标区对象。

    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.

    将底部绘图的 x 轴刻度更改为对数刻度。

    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.

    输入参数

    全部折叠

    刻度值,指定为 "linear""log"。当您更改刻度时,MATLAB® 会将坐标区对象的 XScale 属性更改为您指定的值。

    注意

    当您指定对数刻度时,坐标区在某些情况下可能会排除坐标:

    • 如果坐标包括正值和负值,则仅显示正值。

    • 如果坐标均为负值,所有值都带适当的符号显示在对数刻度上。

    • 不显示零值。

    目标 Axes 对象。如果不指定目标坐标区,xscale 使用当前坐标区。

    版本历史记录

    在 R2023b 中推出

    另请参阅

    函数

    属性