Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

라이선스가 부여된 사용자만 번역 문서를 볼 수 있습니다. 번역 문서를 보려면 로그인하십시오.

gca

Current axes handle

Syntax

Description

example

ax = gca returns the current axes for the current figure. If an axes does not exist, then gca creates one. You can use ax to query and modify axes properties.

Examples

collapse all

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.

Note: Starting in R2014b, you can use dot notation to set properties. If you are using an earlier release, use the set function instead, such as set(ax,'FontSize',12).

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, returned as an axes object or a polar axes object. You can use ax to query and modify axes properties. For a list of properties, see Axes Properties or Polar Axes Properties.

More About

collapse all

Current Axes

The current axes is the target for graphics output. It is the axes in which graphics commands such as plot, text, and surf draw their results. It is typically the last axes created or the last axes clicked with the mouse. Changing the current figure also changes the current axes.

User interaction can change the current axes. If you need to access a specific axes, store the axes handle in your program code when you create the axes and use this handle instead of gca.

Tips

  • To access the current axes without forcing the creation of an axes if one does not exist, query the figure CurrentAxes property. MATLAB® returns an empty array if there is no current axes. Starting in R2014b, you can query properties using dot notation. If you are using an earlier release, use the get function instead, such as ax = get(fig,'CurrentAxes').

    fig = gcf;
    ax = fig.CurrentAxes;

  • Set axes properties after plotting since some plotting functions reset axes properties.

See Also

Functions

Properties

Introduced before R2006a

Was this topic helpful?