ginput() and 2 subplots -- is there a way to show cursor location on BOTH subplots?
16 次查看(过去 30 天)
显示 更早的评论
Hello!
I have a routine which plots contours of two data sets (with the same x and y coordinates) on separate subplots (subplot(1,2,1) and subplot(1,2,2)). I use ginput() to generate a cursor to pick the "best" value. This works on either of the subplots -- I can move the cursor from one to the other subplot and pick the point on either one.
However, I would like to have the cursor position show on each of the subplots so I can tell which is "best" in both representations. Is there either a modification of ginput() or another function to do this?
Any thoughts are welcome.
Regards,
Doug Anderson
2 个评论
采纳的回答
Walter Roberson
2014-1-21
You will need to draw the cursor yourself, perhaps create a hggroup that contains two lines (perhaps the hggroup will not help). Then copyobj() to the second axes, and then linkprop() the position information. Track by checking get(gca, 'CurrentPoint')
You might want to set the figure PointerShapeCData and PointerShapeHotSpot to create a custom pointer that is essentially invisible but has a hotspot (whose location the axes CurrentPoint will track)
更多回答(1 个)
Bruno Pop-Stefanov
2014-1-17
You can specify with ginput how many points you would like to click. It does not depend on how many axes you have. For example, you can use [x,y] = ginput(2) to let the user get 2 points before displaying them. However, I prefer drawing the point selected by the user right after a click.
I use ginput(1) twice. When the user clicks on an axes to select a point, ginput makes it the current axes, which makes drawing the point easier. Here is code that draws points on two subplots using ginput:
x = -pi:0.001:pi;
figure(1);
ax1 = subplot(1,2,1);
line(x, sin(x), 'Color', 'r');
grid on
xlabel('x')
ylabel('y')
title('Select a point')
axis tight
ax2 = subplot(1,2,2);
line(x, cos(2*x).*sin(x).^2, 'Color', 'b');
grid on
xlabel('x')
ylabel('y')
title('Slect a point')
axis tight
% clicking an axes makes it the current axes
[x,y] = ginput(1)
% draw point
line(x, y, 'Color', 'k', 'LineStyle', '+', 'MarkerSize', 20);
% do that again for the other subplot
[x,y] = ginput(1)
% draw point
line(x, y, 'Color', 'k', 'LineStyle', '+', 'MarkerSize', 20);
Let me know if you have more questions or if I didn't answer your question.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Exploration 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!