Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

daspect

Control data unit length along each axis

Syntax

  • daspect auto
  • daspect manual

Description

example

daspect(ratio) sets 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 ratio as a three-element vector of positive values that represent the relative lengths of data units along each axis. For example, [1 2 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].

daspect auto lets 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.

daspect manual uses the ratio stored in the DataAspectRatio property 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.

example

d = daspect returns the data aspect ratio for the current axes.

example

m = daspect('mode') returns the current mode, which is either 'auto' or 'manual'. By default, the mode is automatic unless you specify the data aspect ratio or set the mode to manual.

example

daspect(ax,___) uses 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 daspect(ax,'auto') and daspect(ax,'manual').

Examples

collapse all

Use Equal Data Unit Lengths Along Each Axis

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])

Use Different Data Unit Lengths Along Each Axis

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

Query Data Aspect Ratio

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

Set Data Aspect Ratio for Specific Axes Object

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 daspect function.

ax1 = subplot(2,1,1);
plot(1:10)

ax2 = subplot(2,1,2);
plot(1:10)
daspect(ax2,[1 2 1])

Input Arguments

collapse all

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 DataAspectRatio property for the axes object. The DataAspectRatio property interacts with the PlotBoxAspectRatio, XLim, YLim, and ZLim properties to control the length and scale of the x-axis, y-axis, and z-axis.

Specifying the ratio sets the DataAspectRatioMode property to 'manual' and disables the Stretch-to-fill behavior of the axes.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

ax — Axes objectaxes object

Axes object. If you do not specify an axes object, then daspect uses the current axes (gca).

Output Arguments

collapse all

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 DataAspectRatio property value for the corresponding axes object.

m — Current data aspect ratio mode'auto' | 'manual'

Current data aspect ratio mode, returned as either 'auto' or 'manual'. When the mode is automatic, the axes determines the appropriate data aspect ratio value. If you specify a value, then the mode changes to manual.

Querying the data aspect ratio mode returns the DataAspectRatioMode property value for the corresponding axes object.

More About

collapse all

Stretch-to-fill

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 DataAspectRatio, PlotBoxAspectRatio, and 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 Position property of the axes object determine the available space.

The stretch-to-fill feature is enabled when the DataAspectRatioMode, PlotBoxAspectRatioMode, and 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)

See Also

| | | |

Introduced before R2006a

Was this topic helpful?