How to Draw a Line Between Two Points on Different Axes

조회 수: 11 (최근 30일)
Jacob Smith, PhD
Jacob Smith, PhD 2018년 7월 20일
편집: VIVEK RUHELA 2019년 2월 26일
I have a small plot inlaid on a larger plot. Of course, each plot has its own set of axes. Is there a way to draw a line connecting a point on the first plot with a point on the second plot?
  댓글 수: 2
dpb
dpb 2018년 7월 20일
Hmmm....interesting question! :)
Haven't actually tried to solve that one but it's tied into how the 'position' property of the secondary axes is set compared to the primary and then the difference between the coordinate systems of the canvas and the axes...there's a discussion under the graphics objects section that shows how that's all intertwined...
Good luck, if somebody else doesn't solve it first, I'll try to get back later on after meetings...
Image Analyst
Image Analyst 2018년 7월 20일
Please post a screenshot.

댓글을 달려면 로그인하십시오.

답변 (1개)

Kelly Kearney
Kelly Kearney 2018년 7월 20일
I suggest using annotations paired with the very handy axescoord2figurecoord function:
h.ax(1) = axes('position', [0.1 0.1 0.8 0.8]);
h.ax(2) = axes('position', [0.8 0.1 0.1 0.1]);
x = 1:10;
y = x.^2;
plot(h.ax(1), x,y);
plot(h.ax(2), x,y);
set(gcf, 'units', 'normalized');
axes(h.ax(1));
[xfig(1), yfig(1)] = axescoord2figurecoord(x(5), y(5));
axes(h.ax(2));
[xfig(2), yfig(2)] = axescoord2figurecoord(x(5), y(5));
annotation('line', xfig, yfig);
  댓글 수: 1
VIVEK RUHELA
VIVEK RUHELA 2019년 2월 26일
편집: VIVEK RUHELA 2019년 2월 26일
@Kelly Kearney : This code is not working and I am not able to reproduce the results given by you. The smaller axes is hidden behind the bigger one. How to put it on front. Thanks.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by