Zooming resizes axes
Show older comments
Dear all,
I am working on my first GUI and already [edited] beginning to love it [until here] :-) I am not managing it to obtain stable axes. Here is my code [now edited again, sorry].
Take this as input:
[X,Y] = meshgrid(1:200,1:100);
A = [peaks(100) peaks(100)];
This is the function:
function [] = mygui(X,Y,A)
% place data in structure array so that it is available to each subfunction
S.data.X = X;
S.data.Y = Y;
S.data.A = A;
% set up figure
S.fh = figure('units','pixels',...
'position',[100 100 800 600],...
'menubar','none',...
'name','Manual carving tool',...
'numbertitle','off',...
'resize','off',...
'toolbar','figure');
% set up zoom toolbar
S.tbh = findall(S.fh,'Type','uitoolbar');
S.tbhb = findall(S.tbh);
delete(S.tbhb([2:9 13:end]));
S.tbhb = S.tbhb(10:12);
% axes
S.ax = axes('parent',S.fh,...
'Units','pixels',...
'DataAspectRatio',[1 1 1],...
'DataAspectRatioMode','manual',...
'OuterPosition',[0 0 600 600],...
'Position',[0 0 600 600],...
'Xlimmode','auto',...
'Ylimmode','auto',...
'PlotBoxAspectRatio',[1 1 1],...
'PlotBoxAspectRatioMode','manual',...
'Visible','on',...
'Layer','top',...
'Box','on',...
'Visible','on');
% display A in axes
S.im = image('parent',S.ax,...
'XData',X(1,:),...
'YData',Y(:,1),...
'CData',A,...
'CDataMapping','scaled',...
'visible','on');
So if I now zoom in, the axes position remains at [0 0 600 600], then, if I zoom out and the image extent becomes smaller than the axes, the axes tighten around the image. If I doubleclick on the image, the original position of the axes appears again. However, I would like the axes to remain at the same position always, disregarding the "zoom history". I am using R2011b on Windows.
Thanks for your help, Anon
5 Comments
Sean de Wolski
on 9 Dec 2011
+1 too. Well written question and interesting way of keeping the zoom options.
Perhaps your GUI would behave better if you quit hating it and started being nice to it. You catch more flies with honey than vinegar :)
Anon
on 9 Dec 2011
Sean de Wolski
on 9 Dec 2011
You're welcome!
I'm now not clear on what behavior you want: I'll list what I'm seeing for you to comment on what's good/bad:
1) image is in bottom left corner taking up 5/6 of axes in x/y
2) try to zoom out, can't.
3) zoom in on area complete contained within the image. Image takes up whole axes.
4) pan to edge of image - no white on the outside, can't leave image range.
5) zoom out able to stop at image covering whole axes or back to original 5/6
6) zoom in on edge of image, half stays off image half stay on, ablt to pan onto axes with no image. If I pan on to image completely can't pan back to axes.
What part don't you like (or am I not trying?)
Anon
on 9 Dec 2011
Sean de Wolski
on 9 Dec 2011
See my updated answer.
Accepted Answer
More Answers (1)
karan
on 9 Dec 2011
You really dont need any code for what you are asking. If you want to get what you are asking use the matlab GUIDE.
when you are in your figure file section of your gui...on the top just to the left of the 'm-file editor' there is the 'toolbar editor' go there and add the zooming buttons ... this automatically comes up when u run your gui moreover it resizes te axes itself everytime you zoom in or zoom out.
check out this video and you will know what i am talking about...
i hope this helps
Categories
Find more on Data Exploration 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!