Zooming resizes axes
15 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Sean de Wolski
2011 年 12 月 9 日
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
その他の回答 (1 件)
karan
2011 年 12 月 9 日
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
参考
カテゴリ
Help Center および File Exchange で Data Exploration についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!