Can you set figure axis properties without using gca as argument to the set command?
조회 수: 4 (최근 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!