Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Tooltip for axes object

126 views
Skip to first unread message

Matthias Herzig

unread,
Jul 17, 2002, 9:49:58 AM7/17/02
to
Hi everyone,

I need help on how to add a tooltip to my mouse when I move over an axes
object.
Suppose I have a figure with data over time on a large scale. I do not want
to zoom in to the point. I just want to place the mouse on the figure and
want the dat or time or whatver is associated with this point.

Is there any way to do it?

Any help is greatly appreciated.

Matthias


Brett Shoelson

unread,
Jul 17, 2002, 10:34:48 AM7/17/02
to
Hi Matthias,
Tooltipstrings are only associated with uicontrols, so unless you want to
create each point as a uicontrol of style 'static text', I don't know of any
way to do exactly that. You might try something along these lines, though:

t = [0:pi/64:4*pi];
hold on;
for ii = 1:length(t)
a=text(t(ii),sin(t(ii)),'x','horizontalalignment','center','tag','a');
set(a,'buttondownfcn','tmp = get(gco,''position''); fprintf(''Position:
[%0.1f %0.1f]\n'',tmp(1),tmp(2));
set(findobj(''tag'',''a''),''color'',''k'',''fontweight'',''n'');
set(gco,''color'',''r'',''fontweight'',''b'');');
end
hold off
set(gca,'ylim',[-1, 1],'xlim',[min(t) max(t)]);

(It's possible to do something similar using uicontrols, but the positioning
of your data elements becomes more troublesome.)
Regards,
Brett


"Matthias Herzig" <matthia...@sf.hs-wismar.de> wrote in message
news:3d357...@kermit.rz.hs-wismar.de...

Brett Shoelson

unread,
Jul 17, 2002, 10:52:56 AM7/17/02
to
...or (this may better suit your needs):

t = [0:pi/64:4*pi];
hold on;
for ii = 1:length(t)
a=text(t(ii),sin(t(ii)),'x','horizontalalignment','center','tag','a');
set(a,'buttondownfcn','tmp = get(gco,''position'');

set(postext,''string'',sprintf(''Position: [%0.1f,
%0.1f]\n'',tmp(1),tmp(2)));


set(findobj(''tag'',''a''),''color'',''k'',''fontweight'',''n'');
set(gco,''color'',''r'',''fontweight'',''b'');');
end

postext = text(0.3,-0.9,'');


hold off
set(gca,'ylim',[-1, 1],'xlim',[min(t) max(t)]);

Brett

"Matthias Herzig" <matthia...@sf.hs-wismar.de> wrote in message
news:3d357...@kermit.rz.hs-wismar.de...

Brett Shoelson

unread,
Jul 17, 2002, 10:59:03 AM7/17/02
to
Hi Matthias,
Sorry for the third post, but I just realized that the solution can be even
simpler, since the 'text' command is "vectorized." You don't need the for
loop:


t = [0:pi/64:4*pi];
hold on;

a=text(t,sin(t),'x','horizontalalignment','center','tag','a');


set(a,'buttondownfcn','tmp = get(gco,''position'');
set(postext,''string'',sprintf(''Position: [%0.1f,
%0.1f]\n'',tmp(1),tmp(2)));
set(findobj(''tag'',''a''),''color'',''k'',''fontweight'',''n'');
set(gco,''color'',''r'',''fontweight'',''b'');');

postext = text(0.3,-0.9,'');
hold off
set(gca,'ylim',[-1, 1],'xlim',[min(t) max(t)]);

Cheers (for the last time, I hope),
Brett


"Matthias Herzig" <matthia...@sf.hs-wismar.de> wrote in message
news:3d357...@kermit.rz.hs-wismar.de...

0 new messages