散点图的回调函数

Callback function for scatter plot

我在 Matlab 中有以下散点图:

x = linspace(0,3*pi,200);
y = cos(x) + rand(1,200);  
scatter(x,y)

用户现在应该可以单击散点图中的圆圈。如何确定用户点击了哪个圆圈(即哪个 (x,y) 值)?

在您的回调函数中,您可以使用轴对象的 CurrentPoint 属性 来获取 (x,y) 位置:

loc = get(gca, 'CurrentPoint'); % or use dot notation for later Matlab
loc = loc(1, 1:2); % most of the time we are interested in front xy