Drag a vertical line on subplots

  • Follow


I have a plot that has 3 subplots that are equal in size and stacked above each other.  I need a drag able vertical line that crosses all three subplot for a data visualization problem.  I have looked in all documentation and 'file exchange' but can not find a way to do this. There is a file called 'data_marker'  by Laurens Schalekamp that works on a single plot but not subplots.  Any help would be greatly appreciated....
0
Reply Bruce 6/4/2010 4:51:23 PM

"Bruce Ferguson" <bferguson1@penson.com> wrote in message <hubaub$fpo$1@fred.mathworks.com>...
> I have a plot that has 3 subplots that are equal in size and stacked above each other.  I need a drag able vertical line that crosses all three subplot for a data visualization problem.  I have looked in all documentation and 'file exchange' but can not find a way to do this. There is a file called 'data_marker'  by Laurens Schalekamp that works on a single plot but not subplots.  Any help would be greatly appreciated....


an example... copy/paste into blank file:

function dragdemo

figure
a1=subplot(1,2,1,'buttondownfcn',@clickline,'xlimmode','manual');
a2=subplot(1,2,2,'buttondownfcn',@clickline,'xlimmode','manual');

l1=line([.5 .5],[0 1],'parent',a1,'tag','line1','hittest','off');
l2=line([.5 .5],[0 1],'parent',a2,'tag','line2','hittest','off');

function clickline(src,ev)

set(gcf,'windowbuttonmotionfcn',@dragline)
set(gcf,'windowbuttonupfcn',@dragdone)

function dragline(src,ev)
clicked=get(gca,'currentpoint');
xcoord=clicked(1,1,1);

l1=findobj(gcf,'tag','line1');
l2=findobj(gcf,'tag','line2');

set([l1 l2],'xdata',[xcoord xcoord]);

function dragdone(src,ev)

set(gcf,'windowbuttonmotionfcn','');
set(gcf,'windowbuttonupfcn','');
0
Reply matt 6/4/2010 5:24:25 PM


Bruce Ferguson wrote:
> I have a plot that has 3 subplots that are equal in size and stacked 
> above each other.  I need a drag able vertical line that crosses all 
> three subplot for a data visualization problem.

Would a single line that was drawn from the top of the first to the bottom of 
the third (crossing any empty space between) be acceptable, or does it have to 
be three different lines that act in concert?

If a single line is acceptable then after you have created the subplots, use 
axes() to create an axes that covers over all three plots; set the axes 
visibility off, and use line() to draw the line.

If three lines in concert are needed, then if the coordinate systems for the 
three subplots are the same, then create the three lines and use linkprop() to 
link their Position properties together.
0
Reply Walter 6/4/2010 5:58:46 PM

Walter Roberson <roberson@hushmail.com> wrote in message <hubeva$hkf$1@canopus.cc.umanitoba.ca>...
> Bruce Ferguson wrote:
> > I have a plot that has 3 subplots that are equal in size and stacked 
> > above each other.  I need a drag able vertical line that crosses all 
> > three subplot for a data visualization problem.
> 
> Would a single line that was drawn from the top of the first to the bottom of 
> the third (crossing any empty space between) be acceptable, or does it have to 
> be three different lines that act in concert?
> 
> If a single line is acceptable then after you have created the subplots, use 
> axes() to create an axes that covers over all three plots; set the axes 
> visibility off, and use line() to draw the line.
> 

Yes... A single line that was drawn from the top of the first to the bottom of 
       the third (crossing any empty space between) is exactly what I need...however I did not follow you answer of how to do it....?
> If three lines in concert are needed, then if the coordinate systems for the 
> three subplots are the same, then create the three lines and use linkprop() to 
> link their Position properties together.
0
Reply Bruce 6/4/2010 7:52:05 PM

Bruce Ferguson wrote:
> Walter Roberson <roberson@hushmail.com> wrote in message 

>> If a single line is acceptable then after you have created the 
>> subplots, use axes() to create an axes that covers over all three 
>> plots; set the axes visibility off, and use line() to draw the line.

> Yes... A single line that was drawn from the top of the first to the 
> bottom of       the third (crossing any empty space between) is exactly 
> what I need...however I did not follow you answer of how to do it....?

Line_X_Pos_in_subplot_units = 193.2   %some initial position

%First we have to figure out where the subplots are now, but their positions
%are not necessarily all in the same units

u1 = get(Axes1, 'Units');
u2 = get(Axes2, 'Units');
u3 = get(Axes3, 'Units');

%force them to a common unit

set(Axes1, 'Units', 'Pixel');
set(Axes2, 'Units', 'Pixel');
set(Axes3, 'Units', 'Pixel');

%get coordinates
pos1 = get(Axes1, 'Position');
pos2 = get(Axes2, 'Position');
pos3 = get(Axes3, 'Position');

%put them back to what they were

set(Axes1, 'Units', u1);
set(Axes2, 'Units', u2);
set(Axes3, 'Units', u3);

%now figure out the space the subplots span

pos1x = [pos1(1) pos1(1)+pos1(3)];
pos2x = [pos2(1) pos2(1)+pos2(3)];
pos3x = [pos3(1) pos3(1)+pos3(3)];

pos1y = [pos1(2) pos1(2)+pos1(4)];
pos2y = [pos2(2) pos2(2)+pos2(4)];
pos3y = [pos3(2) pos3(2)+pos3(4)];

minx = min([pos1x(1);pos2x(1);pos3x(1)]);
maxx = max([pos1x(2);pos2x(2);pos3x(2)]);

miny = min([pos1y(1);pos2y(1);pos3y(1)]);
maxy = max([pos1y(2);pos2y(2);pos3y(2)]);

%and create a new axes covering all of them. Do not attempt to use subplot()
%to create this axes, as subplot removes any axes underneath the new axes

coveraxes = axes('Units', 'Pixels', ...
   'Position', [minx miny maxx-minx maxy-miny], ...
   'Visible', 'off');

%and draw a line from top to bottom

LineHandle = line(coveraxes, 'Units', 'Pixel', ...
  'XData', [0; 0], ...
  'YData', [miny; maxy], ...
   'Visible', 'off');

%now switch it over to the same units as subplot 1 so that the X coordinates
%can be in the same terms used for the subplot

set(LineHandle, 'Units', u1);

%and move the line to the initial X position and make it visible

set(LineHandle, 'XData', [Line_X_Pos_in_subplot_units; ...
   Line_X_Pos_in_subplot_units], ...
   'Visible', 'on');


%after this, LineHandle contains the handle of the line you want to allow
%to be draggged
0
Reply Walter 6/4/2010 8:49:43 PM

4 Replies
384 Views

(page loaded in 0.125 seconds)

Similiar Articles:













7/27/2012 3:19:42 PM


Reply: