Main Content

gca

Current axes or chart

Syntax

Description

example

ax= gcareturns the current axes (or standalone visualization) in the current figure. Useaxto get and set properties of thecurrent axes. If there are no axes or charts in the current figure, thengcacreates a Cartesian axes object.

Examples

collapse all

Plot a sine wave.

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

Figure contains an axes object. The axes object contains an object of type line.

Set the font size, tick direction, tick length, andy-axis limits for the current axes. Usegcato refer to the current axes.

ax = gca;% current axesax.FontSize = 12; ax.TickDir ='out'; ax.TickLength = [0.02 0.02]; ax.YLim = [-2 2];

Figure contains an axes object. The axes object contains an object of type line.

Output Arguments

collapse all

Current axes, returned as anAxesobject, aPolarAxesobject, aGeographicAxesobject, or a standalone visualization such as aheatmap.

More About

collapse all

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.

  • AnAxesobject.

  • APolarAxesobject.

  • AGeographicAxesobject.

  • A standalone visualization, which is a chart designed for a special purpose that works independently from other charts. For example, aheatmapis a standalone visualization for observing the interaction between two variables in tabular data.

TheCurrentAxesproperty of a figure stores its current axes.

Tips

  • 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 ongca.

  • 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 figureCurrentAxesproperty. MATLAB®returns an empty array if there is no current axes.

    fig = gcf; ax = fig.CurrentAxes;

Introduced before R2006a