Documentation Center

  • Trials
  • Product Updates

pbaspect

Set or query plot box aspect ratio

Syntax

pbaspect
pbaspect([aspect_ratio])
pbaspect('mode')
pbaspect('auto')
pbaspect('manual')
pbaspect(axes_handle,...)

Description

The plot box aspect ratio determines the relative size of the x-, y-, and z-axes.

pbaspect with no arguments returns the plot box aspect ratio of the current axes.

pbaspect([aspect_ratio]) sets the plot box aspect ratio in the current axes to the specified value. Specify the aspect ratio as three relative values representing the ratio of the x-, y-, and z-axes size. For example, a value of [1 1 1] (the default) means the plot box is a cube (although with stretch-to-fill enabled, it may not appear as a cube). See Tips.

pbaspect('mode') returns the current value of the plot box aspect ratio mode, which can be either auto (the default) or manual. See Remarks.

pbaspect('auto') sets the plot box aspect ratio mode to auto.

pbaspect('manual') sets the plot box aspect ratio mode to manual.

pbaspect(axes_handle,...) performs the set or query on the axes identified by the first argument, axes_handle. If you do not specify an axes handle, pbaspect operates on the current axes.

Examples

expand all

Query Plot Box Aspect Ratio

Plot the function $z = xe^{(-x^2-y^2)}$ over the range $-2 \leq x \leq 2$ and $-2 \leq y \leq 2$ .

[x,y] = meshgrid([-2:.2:2]);
z = x.*exp(-x.^2 - y.^2);
surf(x,y,z)

Query the plot box aspect ratio to show that the plot box is square.

plotboxaspect = pbaspect
plotboxaspect =

     1     1     1

Change the data aspect ratio.

daspect([1,1,1])

Query the plot box aspect ratio to show how it changes to accommodate the specified data aspect ratio.

plotboxaspect = pbaspect
plotboxaspect =

     4     4     1

Make the plot box square again by changing the plot box aspect ratio to [1,1,1].

pbaspect([1,1,1])

More About

expand all

Tips

pbaspect sets or queries values of the axes object PlotBoxAspectRatio and PlotBoxAspectRatioMode properties.

When the plot box aspect ratio mode is auto, the MATLAB® software sets the ratio to [1 1 1], but may change it to accommodate manual settings of the data aspect ratio, camera view angle, or axis limits. See the axes DataAspectRatio property for a table listing the interactions between various properties.

Setting a value for the plot box aspect ratio or setting the plot box aspect ratio mode to manual disables the MATLAB stretch-to-fill feature (stretching of the axes to fit the window). This means setting the plot box aspect ratio to its current value,

pbaspect(pbaspect)

can cause a change in the way the graphs look. See the Remarks section of the axes reference description, "Axes Aspect Ratio Properties" in the 3-D Visualization manual, and "Setting Aspect Ratio" in the MATLAB Graphics manual for a discussion of stretch-to-fill.

See Also

| | | | | | | | |

Was this topic helpful?