Documentation Center

  • Trial Software
  • Product Updates

Understanding Axes Aspect Ratio


Axes shape graphics objects by setting the scaling and limits of each axis. When you create a graph, the values or size of the plotted data automatically determines axis scaling , and then draws the axes to fit the space available for display. Axes aspect ratio properties control how MATLAB® performs the scaling required to create a graph.

By default, the size of the axes MATLAB creates for plotting is normalized to the size of the figure window (but is slightly smaller to allow for borders). If you resize the figure, the size and possibly the aspect ratio (the ratio of width to height) of the axes changes proportionally. This enables the axes to always fill the available space in the window. MATLAB also sets the x-, y-, and z-axis limits to provide the greatest resolution in each direction, again optimizing the use of available space.

This stretch-to-fill behavior is generally desirable; however, you might want to control this process to produce specific results. For example, images need to be displayed in correct proportions regardless of the aspect ratio of the figure window, or you might want graphs always to be a particular size on a printed page.

Axis Scaling

The axis command enables you to adjust the scaling of graphs. By default, MATLAB finds the maxima and minima of the plotted data and chooses appropriate axes ranges. You can override the defaults by setting axis limits.

axis([xmin xmax ymin ymax zmin zmax])

You can control how MATLAB scales the axes with predefined axis options:

  • axis auto returns the axis scaling to its default, automatic mode. v = axis saves the scaling of the axes of the current plot in vector v. For subsequent graphics commands to have these same axis limits, follow them with axis(v).

  • axis manual freezes the scaling at the current limits. If you then set hold on, subsequent plots use the current limits. Specifying values for axis limits also sets axis scaling to manual.

  • axis tight sets the axis limits to the range of the data.

  • axis ij places MATLAB into its "matrix" axes mode. The coordinate system origin is at the upper left corner. The i-axis is vertical and is numbered from top to bottom. The j-axis is horizontal and is numbered from left to right.

  • axis xy places MATLAB into its default Cartesian axes mode. The coordinate system origin is at the lower left corner. The x-axis is horizontal and is numbered from left to right. The y-axis is vertical and is numbered from bottom to top.

Aspect Ratio

The axis command enables you to adjust the aspect ratio of graphs. Normally MATLAB stretches the axes to fill the window. In many cases, it is more useful to specify the aspect ratio of the axes based on a particular characteristic such as the relative length or scaling of each axis. The axis command provides a number of useful options for adjusting the aspect ratio:

  • axis equal changes the current axes scaling so that equal tick mark increments on the x-, y-, and z-axis are equal in length. This makes the surface displayed by sphere look like a sphere instead of an ellipsoid. axis equal overrides stretch-to-fill behavior.

  • axis square makes each axis the same length and overrides stretch-to-fill behavior.

  • axis vis3d freezes aspect ratio properties to enable rotation of 3-D objects and overrides stretch-to-fill. Use this option after other axis options to keep settings from changing while you rotate the scene.

  • axis image makes the aspect ratio of the axes the same as the image.

  • axis auto returns the x-, y-, and z-axis limits to automatic selection mode.

  • axis normal restores the current axis box to full size and removes any restrictions on the scaling of the units. It undoes the effects of axis square. Used in conjunction with axis auto, it undoes the effects of axis equal.

The axis command works by manipulating axes graphics object properties.

axis Command Options

The following three pictures illustrate the effects of three axis options on a cylindrical surface created with the statements

t = 0:pi/6:4*pi;
[x,y,z] = cylinder(4+cos(t),30);

axis normal is the default behavior. MATLAB automatically sets the axis limits to span the data range along each axis and stretches the plot to fit the figure window.

axis square creates an axes that is square regardless of the shape of the figure window. The cylindrical surface is no longer distorted because it is not warped to fit the window. However, the size of one data unit is not equal along all axes (the z-axis spans only one unit while the x-axes and y-axes span 10 units each).

axis equal makes the length of one data unit equal along each axis while maintaining a nearly square plot box. It also prevents warping of the axis to fill the window's shape.

Additional Commands for Setting Aspect Ratio

You can control the aspect ratio of your graph in three ways:

  • Specifying the relative scales of the x-, y-, and z-axes (data aspect ratio)

  • Specifying the shape of the space defined by the axes (plot box aspect ratio)

  • Specifying the axis limits

The following commands enable you to set these values.




Set or query the data aspect ratio


Set or query the plot box aspect ratio


Set or query x-axis limits


Set or query y-axis limits


Set or query z-axis limits

See Manipulating Axes Aspect Ratio for a list of the axes properties that control aspect ratio.

Was this topic helpful?