Main Content

box

Display axes outline

Description

example

box on displays the box outline around the current axes by setting its Box property to "on". This property value is the default for GeographicAxes objects.

box off hides the box outline around the current axes by setting its Box property to "off". This property value is the default for Axes and PolarAxes objects.

box toggles the display of the box outline.

box(visibility) displays or hides the box outline by specifying a visibility value. You can specify visibility as "on", "off", a logical value, or an OnOffSwitchState value.

example

box(target,___) modifies the box outline of the axes, legend, or colorbar specified by target instead of the current axes. Specify target before all other arguments.

Examples

collapse all

Plot a surface and display the box outline around the axes.

[X,Y,Z] = peaks;
surf(X,Y,Z)
box on

Turn off the display of the box outline.

box off

First, plot a surface and display the box outline around the axes. By default, the outline appears around the back planes of the axes because the BoxStyle property of the axes is set to 'back'.

[X,Y,Z] = peaks;
surf(X,Y,Z)
box on

Next, display the outline around the entire axes by setting the BoxStyle property to 'full'. Use dot notation to set properties.

ax = gca;
ax.BoxStyle = 'full';

Create a scatter plot and display the box outline around the axes.

x = rand(10,1);
y = rand(10,1);
scatter(x,y)
box on

Change the color of the box outline in the x-axis direction by setting the XColor property of the axes. Use dot notation to set properties.

ax = gca;
ax.XColor = 'red';

Create two axes using the tiledlayout and nexttile functions. Assign the axes objects to the variables ax1 and ax2, and plot into the axes. Remove the box outline around the lower plot by specifying ax2 as the first input argument to box.

tiledlayout(2,1)
ax1 = nexttile;
plot(ax1,1:10)

ax2 = nexttile;
plot(ax2,1:10)
box(ax2,'off')

Input Arguments

collapse all

Box visibility, specified one of these values:

  • "on" or "off" — A value of "on" displays the box outline, and "off" hides it. You can also specify the character vectors 'on' or 'off'.

  • Numeric or logical 1 (true) or 0 (false) — A value of 1 or true displays the box outline, and 0 or false hides it. (since R2024a)

  • A matlab.lang.OnOffSwitchState value — A value of matlab.lang.OnOffSwitchState.on displays the box outline, and matlab.lang.OnOffSwitchState.off hides it. (since R2024a)

Target axes, legend, or colorbar, specified as one of these items:

  • Any type of axes object.

  • A legend, bubble legend, or colorbar object.

  • An array of axes, legends, or colorbar objects that belong to the same class. To determine the class, use the class function.

If you do not specify this argument, then box modifies the current axes.

Tips

  • Some Cartesian axes properties affect the appearance of the box outline. This table lists a subset of axes properties related to the box outline.

    Axes PropertyDescription
    BoxDisplay of box outline
    BoxStyleStyle of box outline
    XColor, YColor, ZColorBox outline color in the x-axis, y-axis, and z-axis directions
    LineWidthWidth of box outline, tick marks, and grid lines

  • Some polar axes properties affect the appearance of the outline around the polar axes. If you are working with polar axes, then the box command controls the outline display when the theta-axis limits do not span 360 degrees. This table lists a subset of polar axes properties related to the outline.

    PolarAxes PropertyDescription
    BoxDisplay of full outline
    RColor, ThetaColorOutline color
    LineWidthWidth of outline, tick marks, and grid lines

  • Some geographic axes properties affect the appearance of the box outline. This table lists a subset of geographic axes properties related to the box outline.

    GeographicAxes PropertyDescription
    BoxDisplay of box outline
    AxisColorColor of outline, tick values, and labels
    LineWidthWidth of box outline, tick marks, and grid lines

Algorithms

The box function sets the Box property of the Axes, PolarAxes, or GeographicAxes object to either "on" or "off".

Version History

Introduced before R2006a

expand all