Synchronize multiple axes over a visible attribute

Situation

Suppose I have position coordinates at specific points in time. Say the data will look like

data = A[rand(100, 3), sort(rand(100, 1))]

where data(:,1)are the x-coordinates, data(:,2)y-coordinates, data(:,3)height and data(:,4)recording time.

I could easily build this data using

pxy = subplot(2,2,1)            % Plot for X-Y-Data
plot(data(:,1), data(:,2))
ptx = subplot(2,2,2)            % Plot for T-X-Data
plot(data(:,4), data(:,1))
pty = subplot(2,2,3)            % ... and so on
plot(data(:,4), data(:,2))
pth = subplot(2,2,4)
plot(data(:,4), data(:,3))

Now, to view the shapes, it would be great to synchronize the axes.

First thoughts on opportunities

A trivial approach can use linkaxesfor the time axis, for example,

linkaxes([ptx, pty, pth], 'x')

However, this leaves xy-plot unchanged. Thus, a weaker question is how to relate the y axis from ptxto the x axis pxy.

But let's make it more complicated:

Factual question

, , pxy pth. , , pxy, , pxy, pth . , pth pxy , .

, 4 , .

, ?

- hold on.

+3
2

() , , , pxy , (matlab ) .

, P1 = (x1, y1) P2 = (x2, y2), pxy; pth , pxy , P1 P2 pxy? Pth1 Pth2? .. , , (P1 P2) .

, pxy, , : http://www.mathworks.com/matlabcentral/answers/21627-triggering-changes-in-plot-with-zoom-function

+2

. , , , - - .

-, , UserData . ( ) :

sb1 = subplot(1, 2, 1);
plot(data(:,1), data(:,2));
axis equal;
sb2 = subplot(1, 2, 2);
plot(data(:,4), data(:,3));
set(sb1, 'UserData', struct('projection', 'xy', 'data', data, 'link', [sb2]));
set(sb2, 'UserData', struct('projection', 'th', 'data', data, 'link', [sb1]));
panzoom(sb1, 'setlimits');   % Those two lines ensure that the zoom limits won't get changed
panzoom(sb2, 'setlimits');   % over time.

:

z = zoom;
set(z, 'ActionPostCallback', @Track.synchronizePlots);
z = pan;
set(z, 'ActionPostCallback', @Track.synchronizePlots);

, , , :

function synchronizePlots(obj, ax)
    ax = ax.Axes;           
    ud = get(ax, 'UserData');

    if ud.projection == 'xy'
        % That is the part discussed in the comments above,
        % which is, as I freely admit, not very sensible on a strict
        % mathematical point of view. However, the result is good enough for my
        % purpose
        xrange = get(ax, 'XLim');
        yrange = get(ax, 'YLim');
        pointsvisible = ud.data(1,:) >= xrange(1) & ...
                        ud.data(1,:) <= xrange(2) & ...
                        ud.data(2,:) >= yrange(1) & ...
                        ud.data(2,:) <= yrange(2);
        r = [min(ud.data(4, pointsvisible)), max(ud.data(4, pointsvisible))];
        if length(r) == 0  % The trick above may fail if there is no point in the zoom region.
            return         % in that case we just do nothing.
        end
    else
        r = get(ax, 'XLim');  % Straightforward
    end


    for a = ud.link  % The function does not care about the number of figures that have to be changed.
        linkud = get(a, 'UserData');

        if linkud.projection == 'xy'
            % Again, changing the xy-plot is that only part we have to work.
            pointsintime = linkud.data(4,:) >= r(1) & ...
                           linkud.data(4,:) <= r(2);
            xrange = [min(linkud.data(1, pointsintime)), ...
                      max(linkud.data(1, pointsintime))];
            yrange = [min(linkud.data(2, pointsintime)), ...
                      max(linkud.data(2, pointsintime))];
            if length(xrange) > 0
                 set(a, 'XLim', xrange);
                 set(a, 'YLim', yrange);
                 axis(a, 'equal');
            end
        else
            set(a, 'XLim', r);
        end
    end

, - .

+1

All Articles