Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to draw lines cross multiple subplots?

1,101 views
Skip to first unread message

Mutang Fan

unread,
Sep 6, 2008, 7:53:01 AM9/6/08
to
Hi guys,

I want to draw lines cross 2 images so that the start and end points of each line which belong to different images are connected. These 2 points are match points or features after the computation of image correlation.

To my knowledge, I can only draw 2 images in the same figure via subplot. But how to draw a line across those 2 images (subplots) so that related points are connected? I guess that if we can get the coordinate of each subplot we can draw such a line. But I don't know how to get the coordinate of each subplot and then how to get the size (width and height) of each plot. Could you please give me some advice on it? Thanks a lot in advance.

Mutang

Bruno Luong

unread,
Sep 6, 2008, 9:00:04 AM9/6/08
to
"Mutang Fan" <fangxianyon...@cad.zju.edu.cn> wrote in message <g9tqut$sh4$1...@fred.mathworks.com>...

> Hi guys,
>
> I want to draw lines cross 2 images so that the start and end points of each line which belong to different images are connected. These 2 points are match points or features after the computation of image correlation.
>
> To my knowledge, I can only draw 2 images in the same figure via subplot. But how to draw a line across those 2 images (subplots) so that related points are connected? I guess that if we can get the coordinate of each subplot we can draw such a line. But I don't know how to get the coordinate of each subplot and then how to get the size (width and height) of each plot. Could you please give me some advice on it? Thanks a lot in advance.
>

You might create an axis that takes the entire surface of the figure, plot a line on it, and make it invisible.

figure(1); clf(1);
subplot(2,1,1);
plot(rand(1,10));
subplot(2,1,2);
plot(rand(1,10));

ax=axes('Position',[0 0 1 1],'Unit','normalize',...
'parent',1);
plot(ax,[0 1],[0 1],'k');
set(ax,'Xtick',[],'Ytick',[],'Visible','off');

% Bruno

Mutang Fan

unread,
Sep 6, 2008, 10:36:01 PM9/6/08
to
"Bruno Luong" <b.l...@fogale.findmycountry> wrote in message <g9tusk$com$1...@fred.mathworks.com>...

Thanks a lot, Bruno. I have tried what you said. But first I don't understand why plot(ax,[0 1],[0 1],'k') draws an inclined line that connects the bottom left corner to the up right corner. Could you please tell me why? Thanks a lot.

Another question is still I don't know how to draw a line from one pixel in one image to the other pixel in another image. I think the main problem now is how to calculate the start and end points of each line through the coordinates of each image. I mean, although we have the start and end of the 2 matching pixels in 2 images respectively (local coordinates), we still can not draw a line connecting them since we don't know the position of each image in the plot.

In additon, I want to paste an image to demonstrate my target plot in this message. But I don't know how to attach such an image in this message. Could you please tell me how to realize it? Thanks a lot.

Xianyong

Bruno Luong

unread,
Sep 7, 2008, 3:58:02 AM9/7/08
to
"Mutang Fan" <fangxianyon...@cad.zju.edu.cn> wrote in message <g9vemh$dlu$1...@fred.mathworks.com>...

> "Bruno Luong" <b.l...@fogale.findmycountry> wrote in message <g9tusk$com$1...@fred.mathworks.com>...
> > "Mutang Fan" <fangxianyon...@cad.zju.edu.cn> wrote in message <g9tqut$sh4$1...@fred.mathworks.com>...
> > > Hi guys,
> > >
> > > I want to draw lines cross 2 images so that the start and end points of each line which belong to different images are connected. These 2 points are match points or features after the computation of image correlation.
> > >
> > > To my knowledge, I can only draw 2 images in the same figure via subplot. But how to draw a line across those 2 images (subplots) so that related points are connected? I guess that if we can get the coordinate of each subplot we can draw such a line. But I don't know how to get the coordinate of each subplot and then how to get the size (width and height) of each plot. Could you please give me some advice on it? Thanks a lot in advance.
> > >
> >
> > You might create an axis that takes the entire surface of the figure, plot a line on it, and make it invisible.
> >
> > figure(1); clf(1);
> > subplot(2,1,1);
> > plot(rand(1,10));
> > subplot(2,1,2);
> > plot(rand(1,10));
> >
> > ax=axes('Position',[0 0 1 1],'Unit','normalize',...
> > 'parent',1);
> > plot(ax,[0 1],[0 1],'k');
> > set(ax,'Xtick',[],'Ytick',[],'Visible','off');
> >
> > % Bruno
>
> Thanks a lot, Bruno. I have tried what you said. But first I don't understand why plot(ax,[0 1],[0 1],'k') draws an inclined line that connects the bottom left corner to the up right corner. Could you please tell me why? Thanks a lot.

Because I draw a line that connect the point (0,0) to (1,1) of axes "ax". That lower-left and upper-right corners, because ax takes the whole figure. You can set your own unit by using axis command.

>
> Another question is still I don't know how to draw a line from one pixel in one image to the other pixel in another image. I think the main problem now is how to calculate the start and end points of each line through the coordinates of each image. I mean, although we have the start and end of the 2 matching pixels in 2 images respectively (local coordinates), we still can not draw a line connecting them since we don't know the position of each image in the plot.

You need to convert the coordinates from the subplot axe that you need to pass in the plot command on the invisible axe. For each subplot "subax", use commands such as:

set(subax,'Unit','normalize') then
get(subax,'Position',...)
get(subax,'Xlim')
get(subax,'Ylim')

and work down the arithmetic from there.

For more details, see "Properties Controlling Axes Size" in help file.

Bruno

Mutang Fan

unread,
Sep 8, 2008, 11:02:03 AM9/8/08
to

"Bruno Luong" <b.l...@fogale.findmycountry> wrote in message <ga01ia$lr6$1...@fred.mathworks.com>...

Dear Bruno, I see. Thanks a lot for your kind help. I will check more details from the help file you suggested.

Mutang

Paul

unread,
Apr 19, 2012, 1:45:12 PM4/19/12
to
.

Here's a simple hack to get this to work quite easily.

text(20,20,['_____________________________'],'FontSize',10,'Color','r','Rotation',-20)

just mess around with the two 20's to define where the line starts, the number of underscores to define the line length, the fontsize to define the line thickness (also affects length though, so do this first), and the rest is self explanatory.


-Paul
.
0 new messages