Can you set figure axis properties without using gca as argument to the set command?
5 次查看(过去 30 天)
显示 更早的评论
I know you can save a structure variable for the current axis using get(gca); however, that structure seems useless except to list items within it.
For example:
axishandle = get(gca); axishandle.XTick
will display the current x-axis tick values on the command line, but both of the following commands are invalid:
set(axishandle.XTick,[0 0.5 1]) set(axishandle.XTick,'XTick',[0 0.5 1])
However,
set(gca,[0 0.5 1])
is valid--so what is the point of being able to assign a handle to the current axis?
0 个评论
采纳的回答
Robert Cumming
2014-9-9
you are returning the axes properties as a static structure - which cant be edited in the way you have done it, however you could have done:
axishandle = gca
set ( axishandle, 'Xtick', [0 0.5 1] );
FYI: You could also have done:
axishandle = handle(gca); % returns as a handle object of the axes
axishandle.XTick = [0 0.5 1]
The second way is the way HG2 will work when it gets released (as far as I know).
As a note: When I create axes I save the handle to it - I hardly ever use gca for anything...
更多回答(1 个)
Sean de Wolski
2014-9-9
I think you're misunderstanding the handle and output from get.
axHandle = gca
Will give you the handle to the axes. You can think of this as a phone number with which you can query or set the axes.
props = get(gca)
Gives you a static structure of what all of the properties are at the time. This does not update and you would have to rerun it any time you want current properties.
If you want a specific property (rather than all of them), just get it
xt = get(gca,'XTick')
The purpose of being able to store the handle to gca is so that you can have multiple axes and control which one gets the update or whose properties you're querying even if the axes you care about is not current.
axh1 = subplot(1,2,1);
axh2 = subplot(1,2,2);
Now regardless of which one is current I can grab pieces of either.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!