Setting ButtonDownFcn disables default datatip functionality on hover
이전 댓글 표시
Hello,
Matlab nicely has the builtin feature of viewing the data tips when the mosue hovers on a point in a plot.
However, when I try to set the ButtonDownFcn of the plot, this default data tip functionality is disabled.
Is there a way to have both: View data points on hover and fire a function when the plot is clicked?
Example:
figure()
a=plot(1:10,1:10)
%Figure now shows data tips perfectly
set(a,'HitTest', 'on', 'ButtonDownFcn',@(varargin)disp('Anything'))
%Running the last line disables the datatips on hovering to enable firing the disp function when plot is clicked
Many thanks!
댓글 수: 5
Johannes Hougaard
2020년 4월 16일
Hi Ahmad
This is really annoying - I realized the exact same thing when creating a buttondownfcn to identify a given curve in plot of many lines.
Some of the functionality can be restored by calling
datacursormode(gcf,'on');
...it still doesn't allow you to view datatips on hovering, but you can disable your ButtonDownFcn for a while for setting a dataip and then restore it afterwards with.
datacursormode(gcf,'on');
Ahmad Khaled
2020년 4월 16일
Michael Hotto
2021년 12월 14일
편집: Michael Hotto
2021년 12월 14일
I have the same issue, adding a simple ButtonDownFcn disables default mouse hover highlighting and datatips.
When comparing s1 to s2, the only property difference I could identify was the ButtonDownFcn field which is what I would expect.
Johannes's answer before me makes it so you have to physically deselect "Data Tips" in the figure interactivity menu in order for a button down function to work on a selected point. You will also have to deselect "Data Tips" if you want any of the other figure interactivities to work.
Example:
function interactive_sin()
% tested on MATLAB 2021b
X = 0:pi/100:2*pi;
Y = sin(X);
h = figure();
%s1 = scatter(X,Y,'filled'); -> has default MATLAB hover highlighting & datatips
s2 = scatter(X,Y,'filled','ButtonDownFcn',{@selected_pt,h}); % -> does NOT have default MATLAB hover highlighting & datatips
end
% -------------------------------------------------------------------------
function selected_pt(src,event,h)
pt = event.IntersectionPoint;
fprintf('You selected pt: [%0.2f %0.2f]\n',pt(1),pt(2))
% do more stuff with selected pt here but removed from this quick example for simplicity:
%
%
%
end
Jonatha Reis
2022년 6월 17일
Did you manage to solve this issue? I am having the same problem and I just can't find the solution...
Ahmad Khaled
2022년 6월 17일
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!