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

give the data cursor window figure a fixed position

227 views
Skip to first unread message

Franz Petzold

unread,
Aug 17, 2010, 11:04:04 AM8/17/10
to
Hello,
is it possible to give the data cursor window figure a fixed position in a gui or is the data cursor window figure always on the right under side in a figure plot or a gui?
I´m very grateful for any help?

Andy

unread,
Aug 17, 2010, 11:19:04 AM8/17/10
to
"Franz Petzold" <franz-...@web.de> wrote in message <i4e8d4$dcg$1...@fred.mathworks.com>...

> Hello,
> is it possible to give the data cursor window figure a fixed position in a gui or is the data cursor window figure always on the right under side in a figure plot or a gui?
> I´m very grateful for any help?

Create a datatip, right click, and under Display Style select "Window Inside Figure". This will fix a window, which you can click and drag to a location of your choice, which displays the datatip value in the window rather than blocking the graph. Note: I believe you lose the ability to view multiply datatips at the same time.

Franz Petzold

unread,
Aug 18, 2010, 2:47:05 AM8/18/10
to
> Create a datatip, right click, and under Display Style select "Window Inside Figure". This will fix a window, which you can click and drag to a location of your choice, which displays the datatip value in the window rather than blocking the graph. Note: I believe you lose the ability to view multiply datatips at the same time.


Hello, thank you for your answer.
I know that it´s possible to drag the "Window Inside Figure" to a location of my choice.
But I want that "Window Inside Figure" is on a location of my choice by starting a gui.
So it is possible to pretend the position of the "Windows Inside Figure", for example in the middle, or in the left upper corner of a gui?
For my case it would be the best, if i could assign the "Windows Inside Figure" a axes in a gui.

Andy

unread,
Aug 18, 2010, 8:38:06 AM8/18/10
to
"Franz Petzold" <franz-...@web.de> wrote in message <i4fvl9$fgb$1...@fred.mathworks.com>...

%% Try the following
f=figure;
h=datacursormode(f);
set(h,'Displaystyle','Window','Enable','on');
a=axes('Parent',f);
x=1:0.1:10;
y=sin(x);
plot(a,x,y);

% stop here and view the figure
% note the placement of the datatip window

%%
w = findobj('Tag','figpanel');
pos = get(f,'Position');
set(w,'Position',[0 pos(4)-60 200 60]);

% now check placement of the window again
% it should be in the upper left corner


Franz

unread,
Aug 18, 2010, 9:24:21 AM8/18/10
to
"Andy " <myfakeema...@gmail.com> wrote in message <i4gk7e$lk3$1...@fred.mathworks.com>...

Hello Andy,

thank you for your answer and help. This is exactly what I´ve searched for.
Thank you very much. This is magnificent!

Since you help me in this case. I have an another question. Perhaps you can help there too?

I´ve created a gui with two axes on it. My problem is that the text, which is
shown by the data cursor, must be different for both axes.

Now how can I tell the data cursor mode that the data cursor must take the
updatefcn1 when the cursor is on axes1 and take the updatefcn2 when the cursor
is on axes2 ?

The functions are:

for axes1

dcm_obj = datacursormode(...)
set(dcm_obj,'DisplayStyle','datatip',...
'SnapToDataVertex','on','Enable','on')
set(dcm_obj,'UpdateFcn',@updatefcn1)

function txt = updatefcn1(empt,event_obj)
pos = get(event_obj,'Position');
txt = {['x: ',num2str(pos(1))],...
['t: ',num2str(pos(2))]};
if length(pos) > 2
txt{end+1} = ['T(x,t): ',num2str(pos(3))];
end


and for axes2

dcm_obj = datacursormode(...)
set(dcm_obj,'DisplayStyle','datatip',...
'SnapToDataVertex','on','Enable','on')
set(dcm_obj,'UpdateFcn',@updatefcn2)

function txt = updatefcn2(empt,event_obj)
pos = get(event_obj,'Position');
txt = {['Zeit t: ',num2str(pos(1))],...
['TS1(t): ',num2str(pos(2))]};


Now the question is, how the expression in brackets (...) must be correctly
called in this case?
If I have only one axes in a gui the expression in brackets (...) must mean
(gcf). So the data cursor get handle to current figure.

Andy

unread,
Aug 18, 2010, 9:44:20 AM8/18/10
to
I'm not entirely sure this is possible without quite a bit of effort. It's been a while since I've looked into datacursormode, but I'm pretty sure the modes (data cursor mode, zoom mode, etc.) are either on or off for the entire figure. As far as I know, you can't assign the data cursors to a particular axes element.

You could, however, have two different update functions for your data cursor, and switch between them depending on which graph you click on (or hover over). You just need to have the appropriate callback functions (for example, the ButtonDownFcn of the axes) set the update function for your datacursormode object.

Franz

unread,
Aug 19, 2010, 9:20:27 AM8/19/10
to
"Andy " <myfakeema...@gmail.com> wrote in message <i4go3k$7k3$1...@fred.mathworks.com>...

> I'm not entirely sure this is possible without quite a bit of effort. It's been a while since I've looked into datacursormode, but I'm pretty sure the modes (data cursor mode, zoom mode, etc.) are either on or off for the entire figure. As far as I know, you can't assign the data cursors to a particular axes element.
>
> You could, however, have two different update functions for your data cursor, and switch between them depending on which graph you click on (or hover over). You just need to have the appropriate callback functions (for example, the ButtonDownFcn of the axes) set the update function for your datacursormode object.

Hello Andy,
first of all I must say that I´m a beginner in programming.
I´ve tried to solve the problem by using the ButtonDownFcn.
This is what I´ve written in matlab.

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


'SnapToDataVertex','on','Enable','on')

set(handles.axes1,'ButtonDownFcn',{@myupdatefcn1});
set(handles.axes2,'ButtonDownFcn',{@myupdatefcn2});

Although no error in Matlab shows, but it doesn´t work how I want.
So is it possible that you could show me the correct command?
I´d be very grateful.

Andy

unread,
Aug 19, 2010, 9:44:08 AM8/19/10
to
"Franz " <franz-...@web.de> wrote in message <i4jb2r$ose$1...@fred.mathworks.com>...

I'm not at MATLAB right now, so I can't test things out. Could you describe in more detail why this didn't work like you wanted it to? Meanwhile, perhaps you should look at: http://www.mathworks.com/matlabcentral/fileexchange/24861-41-complete-gui-examples

Specifically, question 20 is about using the ButtonDownFcn on an axes.

Franz

unread,
Aug 19, 2010, 10:04:30 AM8/19/10
to
"Andy " <myfakeema...@gmail.com> wrote in message <i4jcf8$rqu$1...@fred.mathworks.com>...

I´ve already looked at the 41 GUI examples. But there is no similar case who describes my problem.
It doesn´t work like I want, because the datatip window or the window inside figure just show me the default strings (X,Y,Z) and doesn´t change to the strings, which I pretend in myupdatefcn1 for axes1 and myupdatefcn for axes2.

Andy

unread,
Aug 19, 2010, 10:14:21 AM8/19/10
to
"Franz " <franz-...@web.de> wrote in message <i4jdle$ha4$1...@fred.mathworks.com>...

You haven't given me enough code to say what the problem might be. But in any case you should stop this approach and follow the advice in your other thread. Also, having multiple threads for the same question makes it very difficult for people trying to help you, since different people will put different advice in different threads. In the future, you should stick to one thread.

Franz

unread,
Aug 19, 2010, 10:27:20 AM8/19/10
to
> You haven't given me enough code to say what the problem might be. But in any case you should stop this approach and follow the advice in your other thread. Also, having multiple threads for the same question makes it very difficult for people trying to help you, since different people will put different advice in different threads. In the future, you should stick to one thread.


That´s right. I´ll notice it for the future. Okay, I´ll follow the advice in the other thread.
Anyway thanks.

0 new messages