Draw a line between two subtitles

I have two two-by-n arrays representing 2d points. These two arrays are built on the same figure, but in two different subtitles. For each point in one of the arrays there is a corresponding point I of another array. I want to show this correspondence by drawing a line from one of the subheadings to another subplot.

The solutions I found are something like:

ah=axes('position',[.2,.2,.6,.6],'visible','off'); % <- select your pos... line([.1,.9],[.1,.9],'parent',ah,'linewidth',5); 

This displays the line in the coordinate system defined by the axis call. For this to work for me, I need a way to change the coordinate system between the subtitle system and the new system. Does anyone know how to do this?

Perhaps there is another way to do this. If so, I would like to know.

+7
matlab
source share
2 answers

First you need to convert the coordinates of the axes to the coordinates of the shapes. Then you can use ANNOTATION to draw lines in the picture.

You can use the data view to convert unit units (ds2nfu) to FileExchange.

Here is a sample code:

 % two 2x5 arrays with random data a1 = rand(2,5); a2 = rand(2,5); % two subplots subplot(211) scatter(a1(1,:),a1(2,:)) % Convert axes coordinates to figure coordinates for 1st axes [xa1 ya1] = ds2nfu(a1(1,:),a1(2,:)); subplot(212) scatter(a2(1,:),a2(2,:)) % Convert axes coordinates to figure coordinates for 2nd axes [xa2 ya2] = ds2nfu(a2(1,:),a2(2,:)); % draw the lines for k=1:numel(xa1) annotation('line',[xa1(k) xa2(k)],[ya1(k) ya2(k)],'color','r'); end 

Make sure your datasets are equal in size.

Edit: The above code will perform data conversion for current axes. You can also do this for specific axes:

 hAx1 = subplot(211); % ... [xa1 ya1] = ds2nfu(hAx1, a1(1,:),a1(2,:)); 
+7
source share

A simple solution is to use the toolbar in the picture window. Just click "Paste" and then "Line."

-one
source share

All Articles