axes
Create Cartesian axes
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(
modifies the axes appearance or controls the way data displays using one or more name-value pair arguments. For example,Name,Value
)'FontSize',14
sets the font size for the axes text. For a list of properties, seeAxes Properties.
axes(
creates the axes in the figure, panel, or tab specified by父
,Name,Value
)父
, instead of in the current figure.
returns theax
= axes(___)Axes
object created. Useax
to query and modify properties of theAxes
object after it is created. For a list of properties, seeAxes Properties.
axes(
使指定的轴或独立的可视化ed bycax
)cax
thecurrent axesand brings the parent figure into focus. This command also makescax
the first object listed in theChildren
property of the figure and sets theCurrentAxes
property of the figure tocax
.
Examples
Position Multiple Axes in Figure
Position twoAxes
objects in a figure and add a plot to each one.
Specify the position of the firstAxes
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 secondAxes
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 theAxes
objects asax1
andax2
.
figure ax1 = axes('Position',[0.1 0.1 0.7 0.7]); ax2 = axes('Position',[0.65 0.65 0.28 0.28]);
Add a plot to eachAxes
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))
Make Axes the Current Axes
Create two overlayedAxes
objects. Then, specify the current axes and add a plot.
First create twoAxes
objects and specify the positions. Display the box outline around each axes. Return theAxes
objects asax1
andax2
.
figure ax1 = axes('Position',[0.1 0.1 .6 .6],'Box','on'); ax2 = axes('Position',[.35 .35 .6 .6],'Box','on');
Makeax1
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)
Create Axes in Tabs
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)
Input Arguments
父
—Parent container
Figure
object|Panel
object|Tab
object|TiledChartLayout
object|GridLayout
object
Parent container, specified as aFigure
,Panel
,Tab
,TiledChartLayout
, orGridLayout
object.
cax
—Axes to make current
Axes
object|PolarAxes
object|GeographicAxes
object|standalone visualization
Axes to make current, specified as anAxes
object, aPolarAxes
object, aGeographicAxes
object, or a standalone visualization such as aheatmap
.
If you want to make an object the current axes without changing the state of the figure, set theCurrentAxes
property of the figure containing that object; for example:
fig = gcf; fig.CurrentAxes = cax;
Name-Value Arguments
Example:axes('Position',[.3 .3 .5 .5])
sets the position.
Specify optional comma-separated pairs ofName,Value
arguments.Name
is the argument name andValue
is the corresponding value.Name
must appear inside single quotes (' '
). You can specify several name and value pair arguments asName1,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, seeAxes Properties.
Position
—Size and location, excluding margin for labels
[0.1300 0.1100 0.7750 0.8150]
(default) |four-element vector
Size and location, excluding a margin for the labels, specified as a four-element vector of the form[left bottom width height]
. By default, MATLAB®measures the values in units normalized to the container. To change the units, set theUnits
property.
The
left
andbottom
elements define the distance from the lower left corner of the container (typically a figure, panel, or tab) to the lower left corner of the position boundary.The
width
andheight
elements are the position boundary dimensions. For axes in a 3-D view, thePosition
property is the smallest rectangle that encloses the axes.
If you want to specify the position and account for the text around the axes, then set theOuterPosition
property instead. These figures show the areas defined by theOuterPosition
values (blue) and thePosition
values (red).
2-D View of Axes | 3-D View of Axes |
---|---|
|
|
For more information on the axes position, seeControl Axes Layout.
Note
Setting this property has no effect when the parent container is aTiledChartLayout
.
OuterPosition
—Size and location, including labels and margin
[0 0 1 1]
(default) |four-element vector
Size and location, including the labels and a margin, specified as a four-element vector of the form[left bottom width height]
. By default, MATLAB measures the values in units normalized to the container. To change the units, set theUnits
property. The default value of[0 0 1 1]
includes the whole interior of the container.
The
left
andbottom
elements define the distance from the lower left corner of the container (typically a figure, panel, or tab) to the lower left corner of the outer position boundary.The
width
andheight
elements are the outer position boundary dimensions.
These figures show the areas defined by theOuterPosition
values (blue) and thePosition
values (red).
2-D View of Axes | 3-D View of Axes |
---|---|
|
|
For more information on the axes position, seeControl Axes Layout.
Note
Setting this property has no effect when the parent container is aTiledChartLayout
.
Units
—Position units
'normalized'
(default) |'inches'
|'centimeters'
|'points'
|'pixels'
|'characters'
Position units, specified as one of these values.
Units |
Description |
---|---|
'normalized' (default) |
Normalized with respect to the container, which is typically the figure or a panel. The lower left corner of the container maps to(0,0) and the upper right corner maps to(1,1) . |
'inches' |
Inches. |
'centimeters' |
Centimeters. |
'characters' |
Based on the default uicontrol font of the graphics root object:
|
'points' |
Typography points. One point equals 1/72 inch. |
'pixels' |
Pixels. Starting in R2015b, distances in pixels are independent of your system resolution on Windows®andMacintoshsystems.
|
When specifying the units as aName,Value
pair during object creation, you must set theUnits
财产之前指定的属性want to use these units, such asPosition
.
More About
Current Axes
The current axes is the default target object for many graphics commands, such asplot
,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.
An
Axes
object.A
PolarAxes
object.A
GeographicAxes
object.A standalone visualization, which is a chart designed for a special purpose that works independently from other charts. For example, a
heatmap
is a standalone visualization for observing the interaction between two variables in tabular data.
Thegca
command returns the current axes, and theCurrentAxes
property of a figure stores its current axes. Thus, if you change the current figure, the current axes also changes.
Version History
See Also
Properties
Functions
Abrir ejemplo
Tiene una versión modificada de este ejemplo. ¿Desea abrir este ejemplo con sus modificaciones?
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina(Español)
- Canada(English)
- United States(English)
Europe
- Belgium(English)
- Denmark(English)
- Deutschland(Deutsch)
- España(Español)
- Finland(English)
- France(Français)
- Ireland(English)
- Italia(Italiano)
- Luxembourg(English)
- Netherlands(English)
- Norway(English)
- Österreich(Deutsch)
- Portugal(English)
- Sweden(English)
- Switzerland
- United Kingdom(English)