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

18 visualizaciones (últimos 30 días)
Paul
Paul el 8 de Jun. de 2020
Comentada: Tommy el 18 de Jun. de 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).

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by