Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Pan and zoom callbacks at once
Date: Wed, 24 Jun 2009 11:08:03 +0000 (UTC)
Organization: TU Berlin
Lines: 29
Message-ID: <h1t1ej$9ob$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1245841683 9995 172.30.248.35 (24 Jun 2009 11:08:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 24 Jun 2009 11:08:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1115354
Xref: news.mathworks.com comp.soft-sys.matlab:550176


Hi!

I have a figure with several subplots and I set the YLims, XLims and the Ticks manually. Now, if the user wants to zoom or to pan the plots (linked together via linkaxes), the axis ticks are worthless of course. That's why I wanted to use the ActionPreCallback for the pan and zoom funtion to set the tickLabelMode to 'auto' again. I encountered some weird issue, I think most of them because I never used callback until now, so I want to know what you think of my solution and what might be a better one too.

In the programm which sets up the subplots these lines are new:

p = pan(gcf);
set(p,'ActionPreCallback',@myprepancallback);
set(p,'Enable','on');
z = zoom(gcf);
set(z,'ActionPreCallback',@myprezoomcallback);
set(z,'Enable','on');

In @myprepancallback and @myprezoomcallback the setting of the TickLabelMode is done, something like

function myprepancallback(obj,evd)
  children = get(gcf,'Children') % 1st children is not subplot, so use 2nd		
  set(children(2),'XTickMode','auto');
  set(children(2),'YTickMode','auto');		
  set(children(2),'XTickLabelMode','auto');
  set(children(2),'YTickLabelMode','auto');		
end

I noticed that the 'set(p,'Enable','on')' adds on children of gcf, but 'set(z,'Enable','on')' removes that object again, why (and zoom is done, so there seems to be no need for a new children) ? 

Any comments on this?

Greetings, 
Norman