Main Content


Set y-axis secondary label

Since R2023b



    ysecondarylabel(label) displays the specified text label as a secondary label on the y-axis of the current axes. If the y-axis already has a secondary label, the specified label replaces it.


    ysecondarylabel(Visible="off") hides the secondary label. You can specify the value of Visible as false or 0 to produce the same result. For example, ysecondarylabel(Visible=0) also hides the label.

    ysecondarylabel(Visible="on") displays the secondary label. You can specify the value of Visible as true or 1 to produce the same result. For example, ysecondarylabel(Visible=true) also displays the label. This syntax has no effect when the label is empty.

    ysecondarylabel("auto") resets the secondary label to its automatic state, which displays a secondary label in some cases. For example, a secondary label might automatically appear when you plot datetime values or very large numbers.


    ysecondarylabel(ax,___) modifies the secondary label for the target axes. Specify the target axes before any of the input argument combinations in the previous syntaxes.


    collapse all

    Plot a vector of wattage values against a vector of voltage values. Then create an x-axis label, a y-axis label, and a secondary label.

    volts = [10 20 30 40 50];
    amps = 0.9;
    watts = volts * amps;
    ysecondarylabel("(1 Watt = 1 J/s)")

    Plot a vector of duration values against a vector of numbers.

    x = 1:5;
    y = minutes([3 1 6 4 10]);

    Hide the secondary label on the y-axis. The "min" label disappears.


    Create two plots in a tiled chart layout. When you call the nexttile function, specify an output argument to get the axes object for later use.

    volts = [10 20 30 40 50];
    % First plot
    amps1 = 0.9;
    watts1 = volts * amps1;
    ax1 = nexttile;
    plot(volts, watts1)
    % Second plot
    amps2 = 1.1;
    watts2 = volts * amps2;
    ax2 = nexttile;

    Add a secondary label, "(1 Watt = 1 J/s)", to the y-axes of both plots by specifying the array [ax1 ax2] as the first argument to the ysecondarylabel function.

    ysecondarylabel([ax1 ax2],"(1 Watt = 1 J/s)")

    Input Arguments

    collapse all

    Label text, specified as a string scalar, string vector, character vector, or cell array of character vectors. To display one line of text, specify a string scalar or character vector. To specify multiple lines of text, specify a string vector or cell array of character vectors.

    Example: ysecondarylabel("Hurray for me!")

    Example: ysecondarylabel('Hurray for you!')

    Target axes, specified as an Axes object or an array of Axes objects.

    If you do not specify the target axes, then ysecondarylabel uses the current axes.

    Version History

    Introduced in R2023b