Current axes or chart
returns the
current axes or chart for the current figure, which is typically the
last one created or clicked with the mouse. Graphics functions, such
as ax
= gcatitle
, target the current axes or chart. Use ax
to
access and modify properties of the axes or chart. If axes or charts
do not exist, then gca
creates Cartesian axes.
User interaction can change the current axes or chart.
It is better to assign the axes or chart to a variable when you create
it instead of relying on gca
.
Changing the current figure also changes the current axes or chart.
Set axes properties after plotting since some plotting functions reset axes properties.
To access the current axes or chart without forcing the creation of Cartesian
axes, use dot notation to query the figure CurrentAxes
property. MATLAB® returns an empty array if there is no current axes.
fig = gcf; ax = fig.CurrentAxes;