ginput() and 2 subplots -- is there a way to show cursor location on BOTH subplots?
17 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Douglas Anderson
il 17 Gen 2014
Commentato: Douglas Anderson
il 21 Gen 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 Commenti
Risposta accettata
Walter Roberson
il 21 Gen 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)
Più risposte (1)
Bruno Pop-Stefanov
il 17 Gen 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.
Vedere anche
Categorie
Scopri di più su Data Exploration in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!