How to enable the data tip interaction functionality when using a custom "ButtonDownFcn" in MATLAB R2023a?

조회 수: 7 (최근 30일)
I am using MATLAB R2023a, and I have a custom "ButtonDownFcn" to display the point clicked in the plot.
x = linspace(0,2*pi,100);
y = sin(x);
p = plot(x,y);
xlabel('x');
ylabel('sin(x)');
% Custom ButtonDownFcn to display point clicked
set(p,'ButtonDownFcn',{@buttondownfcn}); 
function buttondownfcn(~,event)
    pts = event.IntersectionPoint(1:2);
    disp(pts);
end
However, I notice that when using a custom "ButtonDownFcn", I no longer have the default interactivity of a plot (e.g., displaying data tip upon hovering, etc.). How can I enable the data tip interaction functionality when using a custom "ButtonDownFcn"?

채택된 답변

MathWorks Support Team
MathWorks Support Team 2024년 3월 26일
편집: MathWorks Support Team 2024년 3월 26일
Currently, the "ButtonDownFcn" callback does not have the functionality to enable data tip interaction. To enable the data tip interaction functionality in MATLAB R2023a, consider using the "Hit" event instead of a "ButtonDownFcn". Please see the following code snippet for an example.
x = linspace(0,2*pi,100);
y = sin(x);
p = plot(x,y);
xlabel('x');
ylabel('sin(x)');
% Add a Hit event listener
addlistener(p,'Hit',@(src,event)buttondownfcn(src,event));
function buttondownfcn(~,event)
    pts = event.IntersectionPoint(1:2);
    disp(pts);
end

추가 답변 (0개)

태그

제품


릴리스

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by