Main Content

getAxes

Class:matlab.graphics.chartcontainer.ChartContainer
Package:matlab.graphics.chartcontainer

Get axes for chart container subclass

Syntax

ax = getAxes(obj)

Description

ax= getAxes(obj)returns one or more axes objects for a chart that inherits from thematlab.graphics.chartcontainer.ChartContainerbase class.

Input Arguments

expand all

对象的类继承自thematlab.graphics.chartcontainer.ChartContainerbase class.

Output Arguments

expand all

Axes object, or an array of axes objects. The contents ofaxis useful for specifying the target axes when you call plotting functions within your class definition. You can also useaxto set properties on the axes.

Depending on the contents of the chart,axmight be a scalar axes object or an array of axes objects:

  • If the chart does not already contain an axes object,getAxescreates a Cartesian axes and returns it asax.

  • If the chart contains one Cartesian, polar, or geographic axes object,axis returned as that object.

  • If the chart contains multiple axes objects,axis an array of those objects.

getAxes只返回笛卡尔、极地或地理坐标objects. It does not return other types of objects that are descendents of theTiledChartLayout.

Attributes

Protected true

To learn about attributes of methods, seeMethod Attributes.

Examples

expand all

Thesetupmethod is a common place to call plotting functions and set the axes hold state. In both cases, you must specify the target axes.

创建一个setupmethod in your class definition file. Within that method, callgetAxesto get the axes objectax. Then plot two lines by passingaxas the first argument to theplotandholdfunctions. Callhold(ax,'off')at the end of the method.

classdefTwoLinesPlot < matlab.graphics.chartcontainer.ChartContainerproperties% ...endmethods(Access = protected)functionsetup(obj)% Get the axesax = getAxes(obj);% Plot two lines in the axesline1 = plot(ax,[1 2 3 4 5],[3 5 1 4 9]); hold(ax,'on') line2 = plot(ax,[1 2 3 4 5],[30 52 21 9 18]);% Turn off hold statehold(ax,'off')endfunctionupdate(obj)% ...endendend

Define asetupmethod in your class definition file. Within that method, callgetAxesto get the axes objectax. Then set thex-axis color and the font angle for the axes. Callhold(ax,'on')before calling any plotting functions. Then callhold(ax,'off')at the end of the method.

classdefRedAxisPlot < matlab.graphics.chartcontainer.ChartContainerproperties% ...endmethods(Access = protected)functionsetup(obj) ax = getAxes(obj); ax.XColor = [1 0 0]; ax.FontAngle ='italic'; hold(ax,'on')% Call plotting functions% ...hold(ax,'off')endfunctionupdate(obj)% ...endendend

Limitations

  • Setting theOuterPositon,InnerPosition,Position, orPositionConstraintproperties on the axes might produce unexpected results. Instead, configure the position on an instance of your chart.

  • Changing theParentproperty of the axes is not recommended. Instead, specify theParentproperty on an instance of your chart.

Version History

Introduced in R2019b

expand all

Behavior changed in R2020a