Hi, When you create a plot and hover over a data point WITHOUT pressing anything a datatip is displayed. How do I change the callback to display something else or do something else?

90 visualizaciones (últimos 30 días)
figure
plot(1:10, '.-')

Respuestas (1)

Cameron B
Cameron B el 23 de Dic. de 2019
N = 30;
yy = ceil(rand(N,1)*50);
xx = 1:N;
str = cell(1,N);
for pp = 1:N
str{pp} = sprintf('Sample %d',pp);
end
reer = plot(xx,yy,'-o');
sadf = dataTipTextRow('ID =',str);
reer.DataTipTemplate.DataTipRows(end+1:end+2) = sadf;
reer.DataTipTemplate.DataTipRows(3) = reer.DataTipTemplate.DataTipRows(1);
reer.DataTipTemplate.DataTipRows(1) = reer.DataTipTemplate.DataTipRows(4);
reer.DataTipTemplate.DataTipRows = reer.DataTipTemplate.DataTipRows(1:3);
reer.DataTipTemplate.DataTipRows(2).Label = 'Your Y Data =';
reer.DataTipTemplate.DataTipRows(3).Label = 'Your X Data =';
reer.DataTipTemplate.DataTipRows(4).Label = 'Whatever';
Just an example.
  2 comentarios
Imraan Ibrahim
Imraan Ibrahim el 2 de En. de 2020
Hi Cameron B,
Thank you for getting back to me.
I tried your example out and it is almost everything I need.
To progress that further, is it possible to have a callback function do some something outside of the plot, for example have the datapoint I am hovering over be displayed on a uitable?
I know you can have a 'ButtonDownFcn' callback for datatips, but I don't want to be clicking the mouse button, just hovering over.
Are there any events I can be listening to that may be related to DataTipTemplate?
Regards
Imraan
Cameron B
Cameron B el 2 de En. de 2020
function [C] = movebuttonfunc()
N = 30;
yy = ceil(rand(N,1)*50);
xx = 1:N;
str = cell(1,N);
for pp = 1:N
str{pp} = sprintf('Sample %d',pp);
end
reer = plot(xx,yy,'-o');
sadf = dataTipTextRow('ID =',str);
reer.DataTipTemplate.DataTipRows(end+1:end+2) = sadf;
reer.DataTipTemplate.DataTipRows(3) = reer.DataTipTemplate.DataTipRows(1);
reer.DataTipTemplate.DataTipRows(1) = reer.DataTipTemplate.DataTipRows(4);
reer.DataTipTemplate.DataTipRows = reer.DataTipTemplate.DataTipRows(1:3);
reer.DataTipTemplate.DataTipRows(2).Label = 'Your Y Data =';
reer.DataTipTemplate.DataTipRows(3).Label = 'Your X Data =';
reer.DataTipTemplate.DataTipRows(4).Label = 'Whatever';
fig2 = uifigure;
holder = [0,0];
tab = uitable(fig2,'Data',holder,'ColumnName',{'X Coord','Y Coord'});
set (gcf, 'WindowButtonMotionFcn', {@mouseMove,tab});
function mouseMove (src,event,tab)
C = get (gca, 'CurrentPoint');
title(gca, ['(X,Y) = (', num2str(C(1,1)), ', ',num2str(C(1,2)), ')']);
MousePt = [C(1,1),C(1,2)];
tab.Data = MousePt;
end
end

Iniciar sesión para comentar.

Categorías

Más información sobre Labels and Annotations en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by