Current axes or chart




ax = gca 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 title, 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.


collapse all

Plot a sine wave.

x = linspace(0,10);
y = sin(4*x);

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];

Output Arguments

collapse all

Current axes or chart, returned as an Axes object, a PolarAxes object, a GeographicAxes object, or a graphics object whose parent is a Figure, Tab, or Panel object, instead of an Axes object.

For example, a HeatmapChart object can be the current chart since the parent is typically a Figure object. A Stem object cannot be the current chart since the parent is an Axes object.


  • 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;

See Also



Introduced before R2006a