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.
%% 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
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.
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.
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.
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.
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.