Zooming resizes axes

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 comentarios

Sean de Wolski
Sean de Wolski el 9 de Dic. de 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
Anon el 9 de Dic. de 2011
Thanks, Sean! I have edited the example a little and it should run now. Just use
[X,Y,A] = peaks(100);
as input.
Sean de Wolski
Sean de Wolski el 9 de Dic. de 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
Anon el 9 de Dic. de 2011
I hope the following pictures allow me to get a bit clearer. I have taken the peaks example from my first post which is
[X,Y] = meshgrid(1:200,1:100);
A = [peaks(100) peaks(100)];
and not a quadratic example
1) Calling the GUI
http://img31.imageshack.us/img31/2355/83762790.jpg
2) Zoom in
http://img534.imageshack.us/img534/862/88891339.jpg
3) Zoom out (twice). The axes are tight around the image, what I don't want.
http://img716.imageshack.us/img716/4573/86769480.jpg
4) Double clicking brings back the original layout, which is good.
http://img823.imageshack.us/img823/6725/58997684.jpg
Thanks for your help!
Sean de Wolski
Sean de Wolski el 9 de Dic. de 2011
See my updated answer.

Iniciar sesión para comentar.

 Respuesta aceptada

Sean de Wolski
Sean de Wolski el 9 de Dic. de 2011

1 voto

UPDATE Add this to the bottom of your mfile:
%Setup
set(S.ax,'ylimmode','auto','xlimmode','auto'); %reset after image detroyed
h = zoom(S.ax); %build zoom object
zoom reset; %store current setting
set(h,'ActionPostCallback',{@mypostcallback,h}); %set callback
function mypostcallback(~,~,h)
zdir = get(h); get the handle
if(strcmp(zdir.Direction,'out')) %is it going out?
set(h,'ActionPostCallback',[]); %disable the call back to zoom out
zoom('out'); %zoom to original spot
set(h,'ActionPostCallback',{@mypostcallback,h}); %re-enable the callback
end

2 comentarios

Anon
Anon el 9 de Dic. de 2011
No I haven't. But now I did though I am not really getting much wiser. I created a post-callback which sets the axes position back to its original position. But that doesn't have any effect...
S.zh = zoom(S.fh);
set(S.zh,'ActionPostCallback',{@mypostcallback,S});
and
function mypostcallback(varargin)
S = varargin{3};
set(S.ax,'Position',[0 0 600 600],'PlotBoxAspectRatio',[1 1 1]);
end
Anon
Anon el 10 de Dic. de 2011
Thanks, Sean, for your support.
This works fine! The only drawback is, that you zoom out completely, when zooming out. But that's fine with me.

Iniciar sesión para comentar.

Más respuestas (1)

karan
karan el 9 de Dic. de 2011

0 votos

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

1 comentario

Anon
Anon el 9 de Dic. de 2011
The toolbar is not the issue, but the way the axes respond to zooming. Did you read my question? In addition, there is more in the GUI than what I have shown here. And this requires coding.

Iniciar sesión para comentar.

Categorías

Más información sobre Data Exploration en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 9 de Dic. de 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by