Current axes or chart
current axes or chart for the current figure, which is typically the
last one created or clicked with the mouse. Graphics functions, such
ax = gca
title, target the current axes or chart. Use
access and modify properties of the axes or chart. If axes or charts
do not exist, then
gca creates Cartesian axes.
Plot a sine wave.
x = linspace(0,10); y = sin(4*x); plot(x,y)
Set the font size, tick direction, tick length, and y-axis limits for the current axes. Use
gca to refer to the current axes.
ax = gca; % current axes ax.FontSize = 12; ax.TickDir = 'out'; ax.TickLength = [0.02 0.02]; ax.YLim = [-2 2];
ax— Current axes or chart
GeographicAxesobject | graphics object
Current axes or chart, returned as an
Axes object, a
PolarAxes object, a
object, or a graphics object whose parent is a
Panel object, instead of
For example, a
HeatmapChart object can be
the current chart since the parent is typically a
Stem object cannot be the current chart since
the parent is an
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
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
property. MATLAB® returns an empty array if there is no current axes.
fig = gcf; ax = fig.CurrentAxes;