【 MATLAB 】gca 介绍(当前轴或图表)

举报
李锐博恩 发表于 2021/07/15 07:19:46 2021/07/15
【摘要】 gca Current axes or chart Syntax ax = gca Description ax = gca returns the current axes or chart for the current figure, which is typically the last one created or clicked wi...

gca

Current axes or chart

Syntax

ax = gca

Description

ax = gca returns the current axes or chart for the current figure, which is typically the last one created or clicked with the mouse.

ax = gca  返回当前图形的当前轴或图表,通常是用鼠标创建或单击的最后一个轴。

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.

图形功能(例如标题)以当前轴或图表为目标。 使用ax访问和修改轴或图表的属性。 如果轴或图表不存在,则gca创建笛卡尔坐标轴。


Specify Properties for Current 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. 
Note: Starting in R2014b, you can use dot notation to set properties. If you are using an earlier release, use the docid:matlab_ref.f67-432995 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];




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 on gca.

  • 用户交互可以更改当前轴或图表。 最好在创建变量时将轴或图表分配给变量,而不是依赖于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, query the figure CurrentAxes property. MATLAB® returns an empty array if there is no current axes.

  •  

    要在不强制创建笛卡尔坐标轴的情况下访问当前轴或图表,请查询图形CurrentAxes属性。 如果没有当前轴,MATLAB®将返回一个空数组。

    fig = gcf; ax = fig.CurrentAxes;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').
  • 从R2014b开始,您可以使用点表示法查询属性。 如果您使用的是早期版本,请改用get函数,例如ax = get(fig,'CurrentAxes').

上例中,如果加入语句:

fig = gcf; ax = fig.CurrentAxes;

则得到:

ax = 

  Axes - 属性:

             XLim: [0 2]
             YLim: [-100 20]
           XScale: 'linear'
           YScale: 'linear'
    GridLineStyle: '-'
         Position: [0.1300 0.1100 0.7750 0.8150]
            Units: 'normalized'

 

文章来源: reborn.blog.csdn.net,作者:李锐博恩,版权归原作者所有,如需转载,请联系作者。

原文链接:reborn.blog.csdn.net/article/details/83448879

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。