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

20 Ansichten (letzte 30 Tage)
Paul
Paul am 8 Jun. 2020
Kommentiert: Tommy am 18 Jun. 2020
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).

Akzeptierte Antwort

Tommy
Tommy am 8 Jun. 2020
Bearbeitet: Tommy am 8 Jun. 2020
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 Kommentare
Paul
Paul am 18 Jun. 2020
Hi Tommy,
your solution works exactly as it should. Thank you very much for the support.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by