| Products & Services | Industries | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
axes
axes('PropertyName',propertyvalue,...)
axes(h)
h = axes(...)
axes creates an axes graphics object in the current figure using default property values. axes is the low-level function for creating axes graphics objects. MATLAB automatically creates an axes, if one does not already exist, when you issue a command that creates a graph.
axes('PropertyName',propertyvalue,...) creates an axes object having the specified property values. MATLAB uses default values for any properties that you do not explicitly define as arguments. The axes function accepts property name/property value pairs, structure arrays, and cell arrays as input arguments (see the set and get commands for examples of how to specify these data types). These properties, which control various aspects of the axes object, are described in the Axes Properties section. While the basic purpose of an axes object is to provide a coordinate system for plotted data, axes properties provide considerable control over the way MATLAB displays data.
axes(h) makes existing axes h the current axes and brings the figure containing it into focus. It also makes h the first axes listed in the figure's Children property and sets the figure's CurrentAxes property to h. The current axes is the target for functions that draw image, line, patch, rectangle, surface, and text graphics objects.
If you want to make an axes the current axes without changing the state of the parent figure, set the CurrentAxes property of the figure containing the axes:
set(figure_handle,'CurrentAxes',axes_handle)
This command is useful if you want a figure to remain minimized or stacked below other figures, but want to specify the current axes.
h = axes(...) returns the handle of the created axes object.
Use the set function to modify the properties of an existing axes or the get function to query the current values of axes properties. Use the gca command to obtain the handle of the current axes.
The axis (not axes) function provides simplified access to commonly used properties that control the scaling and appearance of axes.
Set default axes properties on the figure and root object levels:
set(0,'DefaultAxesPropertyName',PropertyValue,...) set(gcf,'DefaultAxesPropertyName',PropertyValue,...)
PropertyName is the name of the axes property and PropertyValue is the value you are specifying. Use set and get to access axes properties.
By default, MATLAB stretches the axes to fill the axes position rectangle (the rectangle defined by the last two elements in the Position property). This results in graphs that use the available space in the rectangle. However, some 3-D graphs (such as a sphere) appear distorted because of this stretching, and are better viewed with a specific three-dimensional aspect ratio.
Stretch-to-fill is active when the DataAspectRatioMode, PlotBoxAspectRatioMode, and CameraViewAngleMode are all auto (the default). However, stretch-to-fill is turned off when the DataAspectRatio, PlotBoxAspectRatio, or CameraViewAngle is user-specified, or when one or more of the corresponding modes is set to manual (which happens automatically when you set the corresponding property value).
This picture shows the same sphere displayed both with and without the stretch-to-fill. The dotted lines show the axes rectangle.

When stretch-to-fill is disabled, MATLAB sets the size of the axes to be as large as possible within the constraints imposed by the Position rectangle without introducing distortion. In the picture above, the height of the rectangle constrains the axes size.
Zoom in using aspect ratio and limits:
sphere
set(gca,'DataAspectRatio',[1 1 1],...
'PlotBoxAspectRatio',[1 1 1],'ZLim',[-0.6 0.6])Zoom in and out using the CameraViewAngle:
sphere set(gca,'CameraViewAngle',get(gca,'CameraViewAngle')-5) set(gca,'CameraViewAngle',get(gca,'CameraViewAngle')+5)
Define multiple axes in a single figure window:
axes('position',[.1 .1 .8 .6])
mesh(peaks(20));
axes('position',[.1 .7 .8 .2])
pcolor([1:10;1:10]);

To create a figure select New > Figure from the MATLAB Desktop or a figure's File menu. To add an axes to a figure, click one of the New Subplots icons in the Figure Palette, and slide right to select an arrangement of new axes. For details, see Plotting Tools — Interactive Plotting in the MATLAB Graphics documentation.
axis | cla | clf | figure | gca | grid | subplot | title | view | xlabel | ylabel | zlabel
![]() | aviread | Axes Properties | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |