Control data unit length along each axis
the data aspect ratio for the current axes. The data aspect ratio
is the relative length of the data units along the x-axis, y-axis,
and z-axis. Specify
a three-element vector of positive values that represent the relative
lengths of data units along each axis. For example,
3] indicates that the length from 0 to 1 along the x-axis
is equal to the length from 0 to 2 along the y-axis
and 0 to 3 along the z-axis. For equal data unit
lengths in all directions, use
[1 1 1].
the axes choose the data aspect ratio and sets the associated mode
to automatic. The mode must be automatic to enable the Stretch-to-fill feature of the axes.
the ratio stored in the
for the axes object and sets the associated mode to manual. When the
mode is manual, it disables the stretch-to-fill behavior of the axes.
Specifying a value for the data aspect ratio sets the mode to manual.
the axes specified by
ax instead of the current
axes. Specify an axes object with any of the input argument combinations
in the previous syntaxes. Use single quotes around input arguments
that are character strings, for example
Plot a set of data. Use data units of equal lengths in all directions by setting the data aspect ratio to
[1 1 1].
t = linspace(0,2*pi); x = cos(t); y = sin(t); plot(x,y) daspect([1 1 1])
Plot a set of data. Set the data aspect ratio so that the length of one data unit in the x-axis direction equals the length of two data units in the y-axis direction and z-axis direction (not shown).
t = linspace(0,2*pi); x = cos(t); y = sin(t); plot(x,y) daspect([1 2 2])
When you set the data aspect ratio, the associated mode changes to manual. Query the current data aspect ratio mode.
d = daspect('mode')
d = manual
Create a surface plot and query.
[x,y] = meshgrid(-2:.2:2); z = x.*exp(-x.^2 - y.^2); surf(x,y,z)
Query the data aspect ratio. The ratio indicates that the length of four units in the x-axis direction equals four units in the y-axis direction and one unit in the z-axis direction. For example, the length from 0 to 1 on the x-axis equals the length from 0 to 1 on the y-axis and 0 to 0.25 on the z-axis.
d = daspect
d = 4 4 1
Create a figure with two subplots and return the axes objects from the
subplot function. Set the data aspect ratio for the lower subplot by specifying
ax2 as the first input argument to the
ax1 = subplot(2,1,1); plot(1:10) ax2 = subplot(2,1,2); plot(1:10) daspect(ax2,[1 2 1])
ratio— Data aspect ratiothree-element vector
Data aspect ratio, specified as a three-element vector of positive
values. For example,
daspect([1 2 3]) specifies
that the length of one unit along the x-axis
equals the length of two units along the y-axis
and three units along the z-axis.
Specifying the data aspect ratio sets the
for the axes object. The
interacts with the
ZLim properties to control the length and scale
of the x-axis, y-axis, and z-axis.
Specifying the ratio sets the
'manual' and disables the Stretch-to-fill behavior of the axes.
d— Current data aspect ratio valuesthree-element vector
Current data aspect ratio, returned as a three-element vector of values representing the ratio of the x-axis, y-axis, and z data unit lengths.
Querying the data aspect ratio values returns the
value for the corresponding axes object.
m— Current data aspect ratio mode
Current data aspect ratio mode, returned as either
When the mode is automatic, the axes determines the appropriate data
aspect ratio value. If you specify a value, then the mode changes
Querying the data aspect ratio mode returns the
value for the corresponding axes object.
When the stretch-to-fill feature is enabled, MATLAB® stretches
the axes to fill the available space. Some distortion can occur. Thus,
the axes might not exactly match the data aspect ratio, plot box aspect
ratio, and camera-view angle values stored in its
CameraViewAngle properties. When stretch-to-fill
is disabled, MATLAB makes the axes as large as possible within
the available space and strictly adheres to the property values so
that there is no distortion. The last two elements of the
of the axes object determine the available space.
The stretch-to-fill feature is enabled when the
CameraViewAngleMode properties of the axes
object are all set to
'auto'. If one or more modes
are manual, the feature is disabled. Thus, if you specify the data
aspect ratio, plot box aspect ratio, or camera-view angle, then the
stretch-to-fill feature is disabled.
For example, this figure shows the same plot with and without
the stretch-to-fill feature enabled. The dotted line shows the available
space as defined by the
Position property. In both
versions, the data aspect ratio, plot box aspect ratio, and camera-view
angle values are the same. However, in the left plot, the stretching
introduces some distortion.
|Stretch-to-fill enabled (some distortion)||Stretch-to-fill disabled (no distortion)|