MATLAB Answers

How to Draw a Line Between Two Points on Different Axes

22 views (last 30 days)
Jacob Smith, PhD
Jacob Smith, PhD on 20 Jul 2018
Edited: VIVEK RUHELA on 26 Feb 2019
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?


dpb on 20 Jul 2018
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...

Sign in to comment.

Answers (1)

Kelly Kearney
Kelly Kearney on 20 Jul 2018
I suggest using annotations paired with the very handy axescoord2figurecoord function: = axes('position', [0.1 0.1 0.8 0.8]); = axes('position', [0.8 0.1 0.1 0.1]);
x = 1:10;
y = x.^2;
plot(, x,y);
plot(, x,y);
set(gcf, 'units', 'normalized');
[xfig(1), yfig(1)] = axescoord2figurecoord(x(5), y(5));
[xfig(2), yfig(2)] = axescoord2figurecoord(x(5), y(5));
annotation('line', xfig, yfig);

  1 Comment

VIVEK RUHELA on 26 Feb 2019
@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.

Sign in to comment.