Skip to Main Content Skip to Search
Product Documentation

Understanding Axes Aspect Ratio

Stretch-to-Fill

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.

Specifying 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:

Specifying 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:

The axis command works by manipulating axes graphics object properties.

Example — 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);
surf(x,y,z)

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:

The following commands enable you to set these values.

Command

Purpose

daspect

Set or query the data aspect ratio

pbaspect

Set or query the plot box aspect ratio

xlim

Set or query x-axis limits

ylim

Set or query y-axis limits

zlim

Set or query z-axis limits

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

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS