Incorrect datatip location on interpolated data
显示 更早的评论
I am trying to automatically add datatips to my data, but have found some strange behaviour that I do not know how to solve.
I have reduced it to the following example:
figure;
hPlot = plot(1:10, 10:-1:1);
x = 1.58;
y = interp1(hPlot.XData, hPlot.YData, x); % Get y-coordinate at given x.
hDataTip = datatip(hPlot, x, y, 'SnapToDataVertex', 'off'); % Create the datatip
fprintf('Desired: x = %.2f, y = %.2f\nRealized: x = %.2f, y = %.2f\n', x, y, hDataTip.X, hDataTip.Y);
Which gives the following output:
Desired: x = 1.58, y = 9.42
Realized: x = 2.58, y = 8.42
Any x-coordinate that would round up to the next integer gives this strange result.
The problem can also be clearly seen when animating:
figure; hold on;
hPlot = plot(1:10, 10:-1:1);
hMarker = scatter(1,1, 'ro');
hDataTip = datatip(hPlot, 'SnapToDataVertex', 'off');
for(x = 1:0.04:5)
y = interp1(hPlot.XData, hPlot.YData, x); % Get y-coordinate at given x.
hDataTip.X = x;
hDataTip.Y = y;
hMarker.XData = x;
hMarker.YData = y;
drawnow;
pause(0.01);
end
Which at one point gives the following:

What can I do to make the datatip appear at the location I desire?
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


