Options for displaying data by clicking on a marker in a plot

조회 수: 20 (최근 30일)
Paul
Paul 2020년 6월 8일
댓글: Tommy 2020년 6월 18일
Hello,
is there an option for displaying data in addition to the usual x and y data by clicking on a marker in a plot?
I've plottet the coordinates of broken particles in the xy-plane and I want to display their ID in addition to their respective coordinates. The ID should be disyplayed in the same window as the x and y value (see attachement).

채택된 답변

Tommy
Tommy 2020년 6월 8일
편집: Tommy 2020년 6월 8일
For R2018b and later:
X = rand(10,1);
Y = rand(10,1);
IDs = randi(100,10,1);
s = scatter(X, Y, 'x');
s.DataTipTemplate.DataTipRows(3) = dataTipTextRow('ID', IDs);
For R2018a and earlier, something similar to this:
X = rand(10,1);
Y = rand(10,1);
IDs = randi(100,10,1);
f = figure;
scatter(X, Y, 'x');
dcm = datacursormode(f);
dcm.UpdateFcn = {@customDataTip, IDs};
function txt = customDataTip(~, eventData, IDs)
s = eventData.Target;
pos = eventData.Position;
ID = IDs(s.XData == pos(1) & s.YData == pos(2));
valueFormat = ' \color[rgb]{0 0.6 1}\bf';
removeValueFormat = '\color[rgb]{.25 .25 .25}\rm';
txt = {['X',[valueFormat num2str(pos(1)) removeValueFormat]],...
['Y',[valueFormat num2str(pos(2)) removeValueFormat]],...
['ID',[valueFormat num2str(ID) removeValueFormat]]};
end
  댓글 수: 6
Paul
Paul 2020년 6월 18일
Hi Tommy,
your solution works exactly as it should. Thank you very much for the support.
Tommy
Tommy 2020년 6월 18일
Happy to help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by