|On this page…|
The MATLAB® software automatically determines axis limits, tick mark placement, and tick mark labels whenever you create a graph. However, you can specify these values manually by setting the appropriate property.
When you specify a value for a property controlled by a mode (e.g., the XLim property has an associated XLimMode property), MATLAB sets the mode to manual, enabling you to override automatic specification. Because the default values for these mode properties are automatic, calling high-level functions such as plot or surf resets these modes to auto.
This section discusses the following properties.
Sets the axis range
Specifies whether axis limits are determined automatically by MATLAB or specified manually by the user
Sets the location of the tick marks along the axis
Specifies whether tick mark locations are determined automatically by MATLAB or specified manually by the user
Specifies the labels for the axis tick marks
Specifies whether tick mark labels are determined automatically by MATLAB or specified manually by the user
Sets the direction of increasing axis values
MATLAB determines the limits automatically for each axis based on the range of the data. You can override the selected limits by specifying the XLim, YLim, or ZLim property. For example, consider a plot of the function Ae-αt evaluated with A = 0.25, α = 0.05, and t = 0 to 900.
t = 0:900; plot(t,0.25*exp(-0.05*t))
The plot on the left shows the results. MATLAB selects axis limits that encompass the range of data in both x and y. However, because the plot contains little information beyond t = 100, changing the x-axis limits improves the usefulness of the plot. If the handle of the axes is axes_handle, then the following statement,
creates the plot on the right.
You can use the axis command to set limits on the current axes only.
You can specify either the minimum or maximum value for an axis limit and allow the other limit to autorange. Do this by setting an explicit value for the manual limit and Inf for the automatic limit. For example, the statement
allows MATLAB to determine the maximum x-limit value based on XData. Similarly, the statement
allows MATLAB to determine the minimum x-limit value based on XData.
MATLAB selects the tick mark location based on the data range to produce equally spaced ticks (for linear graphs). You can specify alternative locations for the tick marks by setting the XTick, YTick, and ZTick properties.
For example, if the value 0.075 is of interest for the amplitude of the function Ae-αt, specify tick marks to include that value.
set(gca,'YTick',[0 0.05 0.075 0.1 0.15 0.2 0.25])
For example, to label the y-axis value of 0.075 with the string Cutoff, you can specify all y-axis labels as a string, separating each label with the "|" character.
The XDir, YDir, and ZDir properties control the direction of increasing values on the respective axis. In the default 2-D view, the x-axis values increase from left to right and the y-axis values increase from bottom to top. The z-axis points out of the screen.
You can change the direction of increasing values by setting the associated property to reverse. For example, setting XDir to reverse,
produces a plot whose x-axis decreases from left to right.
In the 3-D view, the y-axis increases from front to back and the z-axis increases from bottom to top.
Setting the x-, y-, and z-directions to reverse,