Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Datatip (Datacursormode)

Subject: Datatip (Datacursormode)

From: Daphne

Date: 9 May, 2008 06:29:07

Message: 1 of 11


A few questions on adding datatips programmatically.

I have some noisy, log-plot data that goes into a complex
(multi-axes) GUI and using a code that we wrote, we
automatically detect areas where we can fit straight lines
(in the log world). I would like to mark the start and end
of those lines with data tips programmatically. That way
if the user wants to manually change them, they have a
starting point of already present tips.

Another related question, is there a way to move the data
tips' flag to the bottom right position programmatically?
That is where we typically want it (otherwise it hides
data) and we end up pulling it there manually all the time.

Last question, can I limit the datacursormode to the
specific axes, so that the user doesn't, by mistake, click
on something in one of the other axes?

Thanks!
Daphne

Subject: Datatip (Datacursormode)

From: helper

Date: 9 May, 2008 09:50:21

Message: 2 of 11

"Daphne " <daphnew_too_nospam@yahoo.com> wrote in message
<g00qvj$4gu$1@fred.mathworks.com>...

> I would like to mark the start and end of those lines
> with data tips programmatically.

Good question. I don't think you can do this. I will
investigate more and get back to you if I find a way,
though.

> Another related question, is there a way to move the data
> tips' flag to the bottom right position programmatically?

You can do this by setting the "DisplayStyle" property of
the datacursor mode to "window".

dcm_obj = datacursormode;
set(dcm_obj,'DisplayStyle','window')


Note, however, that you can only display one data point at
a time using "window". This conflicts with your desire to
have 2 data points (start and end).


> Last question, can I limit the datacursormode to the
> specific axes, so that the user doesn't, by mistake,
click
> on something in one of the other axes?


You cannot eliminate use of the datacursor from a specific
axes directly. You can, however, eliminate use of the
datacursor on specific plots by setting the "HitTest"
property of the line object to "off".

For example:

hPlot = plot(1:10);
set(hPlot,'HitTest','off')

I suppose you can FINDALL objects on a specific axes
of "Type" "line" and set their properties using:

hPlots = findall(h,'type','line');
set(hPlots,'hittest','off')

where "h" is the handle to the axes. However, you will
need to reissue this command whenever a new plot is placed
on that axes.

Good luck

Subject: Datatip (Datacursormode)

From: Daphne

Date: 9 May, 2008 17:35:04

Message: 3 of 11


Thanks, That's very helpful!
If you do find a way to mark the datatips I would
appreciate it.

Daphne


"helper " <spamless@nospam.com> wrote in message
<g016ot$gva$1@fred.mathworks.com>...
> "Daphne " <daphnew_too_nospam@yahoo.com> wrote in
message
> <g00qvj$4gu$1@fred.mathworks.com>...
>
> > I would like to mark the start and end of those lines
> > with data tips programmatically.
>
> Good question. I don't think you can do this. I will
> investigate more and get back to you if I find a way,
> though.
>
> > Another related question, is there a way to move the
data
> > tips' flag to the bottom right position
programmatically?
>
> You can do this by setting the "DisplayStyle" property
of
> the datacursor mode to "window".
>
> dcm_obj = datacursormode;
> set(dcm_obj,'DisplayStyle','window')
>
>
> Note, however, that you can only display one data point
at
> a time using "window". This conflicts with your desire
to
> have 2 data points (start and end).
>
>
> > Last question, can I limit the datacursormode to the
> > specific axes, so that the user doesn't, by mistake,
> click
> > on something in one of the other axes?
>
>
> You cannot eliminate use of the datacursor from a
specific
> axes directly. You can, however, eliminate use of the
> datacursor on specific plots by setting the "HitTest"
> property of the line object to "off".
>
> For example:
>
> hPlot = plot(1:10);
> set(hPlot,'HitTest','off')
>
> I suppose you can FINDALL objects on a specific axes
> of "Type" "line" and set their properties using:
>
> hPlots = findall(h,'type','line');
> set(hPlots,'hittest','off')
>
> where "h" is the handle to the axes. However, you will
> need to reissue this command whenever a new plot is
placed
> on that axes.
>
> Good luck

Subject: Datatip (Datacursormode)

From: helper

Date: 9 May, 2008 22:20:17

Message: 4 of 11

"Daphne " <daphnew_too_nospam@yahoo.com> wrote in message
<g02208$r3i$1@fred.mathworks.com>...
>
> If you do find a way to mark the datatips I would
> appreciate it.


Ok. I found a method. Note that this is undocumented and
is guaranteed to change in future releases, and I'm not
sure what I am really doing, but it does work for now.

If you create a plot using:

  hPlot = plot(X,Y);

And you want to create a datatip at index "I" of the data,
use the following command to get a handle to the datacursor:

 hDC = datacursormode;
 set(hDC,'Enable','off')

Then, use the following commands to create your datatip:

h = createDatatip(hDC, hPlot);
drawnow
set(h,'Position',[X(I) Y(I)],...
  'String',sprintf('X: %s\nY: %s',...
  num2str(X(I)),num2str(Y(I))));


However, if you want to create more than one datatip at a
time, note that the next call to createDatatip messes
things up for some reason. Therefore, issue all
createDatatip commands at first, then set the properties.
For example:

I = [3 8];
for n = 1:length(I)
  h(n) = createDatatip(hDC, hPlot);
end
drawnow
for n = 1:length(I)
set(h(n),'Position',[X(I(n)) Y(I(n))],...
  'String',sprintf('X: %s\nY: %s',...
  num2str(X(I(n))),num2str(Y(I(n)))));
end

I found many variations and different methods, but this one
seems to work.

Subject: Datatip (Datacursormode)

From: Daphne

Date: 10 May, 2008 08:13:03

Message: 5 of 11


This works great. Thanks!

Another small question. What I want to do, now the the
datatips are plotted, is let the user change their
locations manually, if needed. However, when I set the
datacursormode to on, and try to move one of the datatips,
it doesn't move to the next point on the plot, but falls
to the first one. Any ideas?

Thanks,
Daphne


"helper " <spamless@nospam.com> wrote in message <g02in1
$mhk$1@fred.mathworks.com>...
> "Daphne " <daphnew_too_nospam@yahoo.com> wrote in
message
> <g02208$r3i$1@fred.mathworks.com>...
> >
> > If you do find a way to mark the datatips I would
> > appreciate it.
>
>
> Ok. I found a method. Note that this is undocumented
and
> is guaranteed to change in future releases, and I'm not
> sure what I am really doing, but it does work for now.
>
> If you create a plot using:
>
> hPlot = plot(X,Y);
>
> And you want to create a datatip at index "I" of the
data,
> use the following command to get a handle to the
datacursor:
>
> hDC = datacursormode;
> set(hDC,'Enable','off')
>
> Then, use the following commands to create your datatip:
>
> h = createDatatip(hDC, hPlot);
> drawnow
> set(h,'Position',[X(I) Y(I)],...
> 'String',sprintf('X: %s\nY: %s',...
> num2str(X(I)),num2str(Y(I))));
>
>
> However, if you want to create more than one datatip at
a
> time, note that the next call to createDatatip messes
> things up for some reason. Therefore, issue all
> createDatatip commands at first, then set the
properties.
> For example:
>
> I = [3 8];
> for n = 1:length(I)
> h(n) = createDatatip(hDC, hPlot);
> end
> drawnow
> for n = 1:length(I)
> set(h(n),'Position',[X(I(n)) Y(I(n))],...
> 'String',sprintf('X: %s\nY: %s',...
> num2str(X(I(n))),num2str(Y(I(n)))));
> end
>
> I found many variations and different methods, but this
one
> seems to work.

Subject: Datatip (Datacursormode)

From: helper

Date: 10 May, 2008 22:57:03

Message: 6 of 11

> Another small question. What I want to do, now the the
> datatips are plotted, is let the user change their
> locations manually, if needed. However, when I set the
> datacursormode to on, and try to move one of the
datatips,
> it doesn't move to the next point on the plot, but falls
> to the first one. Any ideas?


Quoting myself:

"Note that this is undocumented and is guaranteed to change
in future releases, and *I'm not sure what I am really
doing*, ..."

I do see the same behavior when I click one of the datatips
then use the arrow keys. I'll look into it some more and
get back to ya.

Subject: Datatip (Datacursormode)

From: helper

Date: 11 May, 2008 02:58:03

Message: 7 of 11

"Daphne " <daphnew_too_nospam@yahoo.com> wrote in message
<g03lef$c19$1@fred.mathworks.com>...
>
> This works great. Thanks!
>
> Another small question. What I want to do, now the the
> datatips are plotted, is let the user change their
> locations manually, if needed. However, when I set the
> datacursormode to on, and try to move one of the
datatips,
> it doesn't move to the next point on the plot, but falls
> to the first one. Any ideas?
>

OK, I've added one more line to the 2nd FOR-loop. I'll dig
more and try to find the ideal way to actually do all of
this rather than this hack.

I = [3 8];
for n = 1:length(I)
  h(n) = createDatatip(hDC, hPlot);
end
drawnow
for n = 1:length(I)
  set(h(n),'Position',[X(I(n)) Y(I(n))],...
    'String',sprintf('X: %s\nY: %s',...
    num2str(X(I(n))),num2str(Y(I(n)))));
   set(get(h(n),'DataCursor'),'DataIndex',I(n))
end

Subject: Datatip (Datacursormode)

From: Daphne

Date: 11 May, 2008 11:48:03

Message: 8 of 11


Well, the hack works really well for now.
Thanks for taking this on. The entire lab is grateful!

Daphne


"helper " <spamless@nospam.com> wrote in message
<g05nbr$kdi$1@fred.mathworks.com>...
> "Daphne " <daphnew_too_nospam@yahoo.com> wrote in
message
> <g03lef$c19$1@fred.mathworks.com>...
> >
> > This works great. Thanks!
> >
> > Another small question. What I want to do, now the the
> > datatips are plotted, is let the user change their
> > locations manually, if needed. However, when I set the
> > datacursormode to on, and try to move one of the
> datatips,
> > it doesn't move to the next point on the plot, but
falls
> > to the first one. Any ideas?
> >
>
> OK, I've added one more line to the 2nd FOR-loop. I'll
dig
> more and try to find the ideal way to actually do all of
> this rather than this hack.
>
> I = [3 8];
> for n = 1:length(I)
> h(n) = createDatatip(hDC, hPlot);
> end
> drawnow
> for n = 1:length(I)
> set(h(n),'Position',[X(I(n)) Y(I(n))],...
> 'String',sprintf('X: %s\nY: %s',...
> num2str(X(I(n))),num2str(Y(I(n)))));
> set(get(h(n),'DataCursor'),'DataIndex',I(n))
> end

Subject: Datatip (Datacursormode)

From: Y

Date: 23 Jul, 2008 16:32:02

Message: 9 of 11

"helper " <spamless@nospam.com> wrote in message
<g016ot$gva$1@fred.mathworks.com>...
> "Daphne " <daphnew_too_nospam@yahoo.com> wrote in message
> <g00qvj$4gu$1@fred.mathworks.com>...
>
> > I would like to mark the start and end of those lines
> > with data tips programmatically.
>
> Good question. I don't think you can do this. I will
> investigate more and get back to you if I find a way,
> though.

Well this is a good question... and I don't succeed in!...
Is there any experienced people about that please ?

Subject: Datatip (Datacursormode)

From: Tim Farajian

Date: 23 Jul, 2008 18:03:04

Message: 10 of 11

Check the file exchange function MAKEDATATIP.

Subject: Datatip (Datacursormode)

From: hassene

Date: 11 Mar, 2009 21:00:19

Message: 11 of 11


> > You cannot eliminate use of the datacursor from a
> specific
> > axes directly. You can, however, eliminate use of the
> > datacursor on specific plots by setting the "HitTest"
> > property of the line object to "off".
> >
> > For example:
> >
> > hPlot = plot(1:10);
> > set(hPlot,'HitTest','off')
> >
> > I suppose you can FINDALL objects on a specific axes
> > of "Type" "line" and set their properties using:
> >
> > hPlots = findall(h,'type','line');
> > set(hPlots,'hittest','off')
> >
> > where "h" is the handle to the axes. However, you will
> > need to reissue this command whenever a new plot is
> placed
> > on that axes.
 thanks you for the hint, i used it in some cases, however i still need to use the samething for the case of a nichols chart: it gives me this error message :
"??? There is no 'hittest' property in the 'nicholsplot' class."
Any help pls ?

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us