| MATLAB® | ![]() |
| On this page… |
|---|
MATLAB® software provides a number of properties for labeling and controlling the appearance of axes. For example, this surface plot shows some of the labeling possibilities and indicates the controlling property.

To create this axes, specify values for the indicated properties.
h = axes('Color',[.9 .9 .9],...
'GridLineStyle','--',...
'ZTickLabel','-1|Z = 0 Plane|+1',...
'FontName','times',...
'FontAngle','italic',...
'FontSize',14,...
'XColor',[0 0 .7],...
'YColor',[0 0 .7],...
'ZColor',[0 0 .7]);
The individual axis labels are text objects whose handles are normally hidden from the command line (their HandleVisibility property is set to callback). You can use the xlabel, ylabel, zlabel, and title functions to create axis labels. However, these functions affect only the current axes. If you are labeling axes other than the current axes by referencing the axes handle, then you must obtain the text object handle from the corresponding axes property.
For example,
get(axes_handle,'XLabel')
returns the handle of the text object used as the x-axis label. Obtaining the text handle from the axes is useful in M-files and MATLAB applications where you cannot be sure the intended target is the current axes.
The following statements define the x- and y-axis labels and title for the axes above.
set(get(axes_handle,'XLabel'),'String','Values of X')
set(get(axes_handle,'YLabel'),'String','Values of Y')
set(get(axes_handle,'Title'),'String','\fontname{times}\itZ =
f(x,y)')
Because the labels are text, you must specify a value for the String property, which is initially set to the empty string (i.e., there are no labels).
MATLAB overrides many of the other text properties to control positioning and orientation of these labels. However, you can set the Color, FontAngle, FontName, FontSize, FontWeight, and String properties.
Note that both axes objects and text objects have font specification properties. The call to the axes function on the previous page set values for the FontName, FontAngle, and FontSize properties.
If you want to specify the font for the labels and title, set the font property values when defining their String property. For example, the x-axis label statement would be
set(get(h,'XLabel'),'String','Values of X',...
'FontName','times',...
'FontAngle','italic',...
'FontSize',14)Bitmapped fonts (e.g., Courier) cannot be rotated on the display. Therefore, when you specify a bitmapped font with the FontName property, this text might not be rotated correctly, for example, when used as the y-axis label.
To avoid problems with bitmapped fonts, use TrueType® fonts. For example, you might have a TrueType font named Courier New that you can use instead of Courier. See your system documentation for information on which fonts are installed on your system.
![]() | Axes Objects — Defining Coordinate Systems for Graphs | Positioning Axes | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |