axes - Create Cartesian axes - MATLAB (original) (raw)

Syntax

Description

axes creates the default Cartesian axes in the current figure and makes it the current axes. Typically, you do not need to create axes before plotting since graphics functions automatically create axes when plotting if they do not exist.

axes([Name,Value](#namevaluepairarguments)) modifies the axes appearance or controls the way data displays using one or more name-value pair arguments. For example, 'FontSize',14 sets the font size for the axes text. For a list of properties, see Axes Properties.

example

axes([parent](#buzt7yy%5Fsep%5Fmw%5F58c53d12-c3c1-4fe8-b606-f6a109982a64),[Name,Value](#namevaluepairarguments)) creates the axes in the figure, panel, or tab specified by parent, instead of in the current figure.

example

`ax` = axes(___) returns the Axes object created. Use ax to query and modify properties of the Axes object after it is created. For a list of properties, see Axes Properties.

axes([cax](#buzt7yy-cax)) sets the CurrentAxes property of the parent figure to be cax. If theHandleVisibilty property of the parent figure is set to"on", then cax also becomes the current axes. This command also makes cax the first object listed in theChildren property of the parent object. The parent object is typically a figure or a tiled chart layout.

Examples

collapse all

Position two Axes objects in a figure and add a plot to each one.

Specify the position of the first Axes object so that it has a lower left corner at the point (0.1 0.1) with a width and height of 0.7. Specify the position of the second Axes object so that it has a lower left corner at the point (0.65 0.65) with a width and height of 0.28. By default, the values are normalized to the figure. Return the Axes objects as ax1 and ax2.

figure ax1 = axes('Position',[0.1 0.1 0.7 0.7]); ax2 = axes('Position',[0.65 0.65 0.28 0.28]);

Figure contains 2 axes objects. Axes object 1 is empty. Axes object 2 is empty.

Add a plot to each Axes object. Specify the axes by passing it as the first input argument to the graphics function. Most graphics functions reset some axes properties, such as the tick values and labels. However, they do not reset the axes position.

contour(ax1,peaks(20)) surf(ax2,peaks(20))

Figure contains 2 axes objects. Axes object 1 contains an object of type contour. Axes object 2 contains an object of type surface.

Create two overlaid Axes objects. Then, specify the current axes and add a plot.

First create two Axes objects and specify the positions. Display the box outline around each axes. Return the Axes objects as ax1 and ax2.

figure ax1 = axes('Position',[0.1 0.1 .6 .6],'Box','on'); ax2 = axes('Position',[.35 .35 .6 .6],'Box','on');

Figure contains 2 axes objects. Axes object 1 is empty. Axes object 2 is empty.

Make ax1 the current axes. This action brings the axes to the front of the display and makes it the target for subsequent graphics functions. Add a line plot to the axes.

axes(ax1) x = linspace(0,10); y = sin(x); plot(x,y)

Figure contains 2 axes objects. Axes object 1 is empty. Axes object 2 contains an object of type line.

Create a figure with two tabs. Add axes to each tab by specifying the parent container for each one. Plot a line in the first tab and a surface in the second tab.

figure tab1 = uitab('Title','Tab1'); ax1 = axes(tab1); plot(ax1,1:10)

tab2 = uitab('Title','Tab2'); ax2 = axes(tab2); surf(ax2,peaks)

Figure contains 2 axes objects and another object of type uitabgroup. Axes object 1 contains an object of type surface. Axes object 2 contains an object of type line.

Input Arguments

collapse all

Parent container, specified as a Figure, Panel,Tab, TiledChartLayout, or GridLayout object.

Axes to make current, specified as an Axes object, aPolarAxes object, a GeographicAxes object, or a standalone visualization such as a heatmap.

If you want to make an object the current axes without changing the state of the figure, set the CurrentAxes property of the figure containing that object; for example:

fig = gcf; fig.CurrentAxes = cax;

This approach is useful if you want a figure to remain minimized or stacked below other figures, but want to specify the current axes.

Name-Value Arguments

collapse all

Example: axes('Position',[.3 .3 .5 .5]) sets the position.

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments as Name1,Value1,...,NameN,ValueN.

Some graphics functions change axes property values when plotting, such as the axis limits or tick values. Set axes properties after plotting.

Note

The properties listed here are only a subset. For a full list, see Axes Properties.

More About

collapse all

The current axes is the default target object for many graphics commands, such as plot, title, andxlim. The following types of objects can become the current axes. Typically, it is the last one of these objects that is created, clicked on, or plotted into.

The gca command returns the current axes, and the CurrentAxes property of a figure stores its current axes. Thus, if you change the current figure, the current axes also changes.

Version History

Introduced before R2006a