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!