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 个评论
Douglas Anderson
Douglas Anderson 2014-1-21
Yes, they have the exact same Xlim and Ylim; only what is plotted on the contour plot itself is different. I would basically like to see if I pick a point on one subplot, what am I picking on the other subplot?
In fact, to be more specific, one of the plots contours the peak value of a synthetic waveform as a function of two variables, and the other contours the sum of the power spectrum of the same synthetic waveform as a function of the same two variables. So it is basically comparing time domain response with frequency domain response, where both responses are reduced to one value for each x and y point.

请先登录,再进行评论。

采纳的回答

Walter Roberson
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 个评论
Douglas Anderson
Douglas Anderson 2014-1-21
Thank you. I kind of figured it might not be "trivial". If I get it working, I'll post the solution; if I just let it ride, I won't.
Thanks again!

请先登录,再进行评论。

更多回答(1 个)

Bruno Pop-Stefanov
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.
  1 个评论
Douglas Anderson
Douglas Anderson 2014-1-21
Thank you very much for your suggestion, and it works nicely for what you have shown. However, as I indicated in my response to Walter's comment, I am looking for a slightly different response -- basically to see two crosshairs, one on each of the subplots, so that picking one visually shows what the result is on the other.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Exploration 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by