How to set the axes limits within a GUI
3 views (last 30 days)
Show older comments
I can plot to a figure and set the axis with the command:
axis([0 900 -1 1])
I want to do the same for a set of axes within my GUI. I can't seem to figure this one out, any suggestions?
0 Comments
Accepted Answer
Matt Fig
on 6 May 2011
You probably need to find the handle to the axes object.
Ax = findall(0,'type','axes')
axis(Ax,[-1 1 -4 4])
Assuming this is GUIDE GUI...
What you left out is from where it is that you are trying to set the limits. If it is from within a callback, you should be able to access the axes handle by using the handles structure. If you are doing it from the command line, then the above will work.
Notice, however, that if you have a legend on the axes, Ax will contain two handles. In that case you will have to perform further tests to see which one is the correct handle. To avoid this you could give the axes a tag, then use the tag when searching with FINDALL.
%
%
%
EDIT In response to your 'answer' below.
Please put comments on answers in the comments, don't start another 'answer'.
So put this in your callback and show what dumps to the screen when you execute the callback:
findall(0,'type','axes')
handles.axes2
Also, are there other plotting commands executed after you change the limits? I.e., do you call PLOT, LINE, PATCH, or any function which interacts with the axes? The call to AXIS should be the last thing you do with the axes...
4 Comments
Matt Fig
on 6 May 2011
O.k., so now do you call any other plotting type functions after the call to AXIS? See if you can change the limits by doing this from the command line:
Ax = findall(0,'type','axes')
axis(Ax(2),[0 900 -1 1]) % Now we know which is axes2
More Answers (0)
See Also
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!