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 ビュー (過去 30 日間)
figure
plot(1:10, '.-')

回答 (1 件)

Cameron B
Cameron B 2019 年 12 月 23 日
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 件のコメント
Imraan Ibrahim
Imraan Ibrahim 2020 年 1 月 2 日
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 2020 年 1 月 2 日
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

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLabels and Annotations についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by