ginput() and 2 subplots -- is there a way to show cursor location on BOTH subplots?
    12 views (last 30 days)
  
       Show older comments
    
    Douglas Anderson
 on 17 Jan 2014
  
    
    
    
    
    Commented: Douglas Anderson
 on 21 Jan 2014
            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 Comments
Accepted Answer
  Walter Roberson
      
      
 on 21 Jan 2014
        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)
More Answers (1)
  Bruno Pop-Stefanov
    
 on 17 Jan 2014
        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.
See Also
Categories
				Find more on Data Exploration in Help Center and File Exchange
			
	Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

