Zooming resizes axes

11 Ansichten (letzte 30 Tage)
Anon
Anon am 9 Dez. 2011
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 Kommentare
Anon
Anon am 9 Dez. 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 am 9 Dez. 2011
See my updated answer.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Sean de Wolski
Sean de Wolski am 9 Dez. 2011
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 Kommentare
Anon
Anon am 9 Dez. 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 am 10 Dez. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

karan
karan am 9 Dez. 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
  1 Kommentar
Anon
Anon am 9 Dez. 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Visual Exploration finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by