필터 지우기
필터 지우기

ginput() and 2 subplots -- is there a way to show cursor location on BOTH subplots?

조회 수: 22 (최근 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
Walter Roberson 2014년 1월 17일
Do the subplots have exactly the same axis limits? XLim and YLim ?
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에서 Axis Labels에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by