## Individual Axis Control

### Properties Controlling Axis Limits

MATLAB 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.

Property

Purpose

XLim,YLim,ZLim

Sets the axis range

XLimMode,

YLimMode,

ZLimMode

Specifies whether axis limits are determined automatically by MATLAB or specified manually by the user

XTick,

YTick,

ZTick

Sets the location of the tick marks along the axis

XTickMode,

YTickMode,

ZTickMode

Specifies whether tick mark locations are determined automatically by MATLAB or specified manually by the user

XTickLabel,

YTickLabel,

ZTickLabel

Specifies the labels for the axis tick marks

XTickLabelMode

YTickLabelMode

ZTickLabelMode

Specifies whether tick mark labels are determined automatically by MATLAB or specified manually by the user

XDir,YDir,ZDir

Sets the direction of increasing axis values

### Setting Axis Limits

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 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,

```set(axes_handle,'XLim',[0 100])
```

creates the plot on the right.

You can use the axis command to set limits on the current axes only.

#### Semiautomatic Limits

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

```set(axes_handle,'XLim',[0 Inf])
```

sets the XLimMode property to auto and allows MATLAB to determine the maximum value for XLim. Similarly, the statement

```set(axes_handle,'XLim',[-Inf 800])
```

sets the XLimMode property to auto and allows MATLAB to determine the minimum value for XLim.

### Setting Tick Mark Locations

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 , specify tick marks to include that value.

```set(gca,'YTick',[0 0.05 0.075 0.1 0.15 0.2 0.25])
```

You can change tick labeling from numbers to strings using the XTickLabel, YTickLabel, and ZTickLabel properties.

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.

```set(gca,'YTickLabel','0|0.05|Cutoff|0.1|0.15|0.2|0.25')
```

### Changing Axis Direction

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,

```set(gca,'XDir','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,

`set(gca,'XDir','rev','YDir','rev','ZDir','rev')`

yields