필터 지우기
필터 지우기

link x-axis from one figure with y-axis from another figure

조회 수: 13 (최근 30일)
Stefan
Stefan 2015년 2월 19일
답변: Titus Edelhofer 2015년 2월 19일
Dear reader,
I am looking for a matlab code that can link the x-axis from figure1 with the y-axis from figure2. I need this functionality in order to simplify the visual inspection of 2 figures. Any help is highly appreciated.
For example, this code links the x-axis of both figures:
x=1:5;
figure;
plot(x);
a1 = gca;
figure;
p2 = plot(x+1);
a2 = gca;
linkaxes([a1 a2],'x');
Notice that now, as the user pans/zooms on figure1, there will be an immediate consequence on figure2. How can I modify this code such that it links x-axis from figure1 to y-axis of figure2?
Thank you,

채택된 답변

Giorgos Papakonstantinou
Giorgos Papakonstantinou 2015년 2월 19일
You could create a callback and then add a listener. So a minimal example would be:
CallBack:
function test(src, evt, ax)
set(ax, 'Ylim', get(gca, 'Xlim'))
end
Your figure:
x=1:5;
figure;
a1 = subplot(1,2,1);
plot(x);
a2 = subplot(1,2,2);
p2 = plot(x+1);
drawnow
xLimListener = addlistener( a1, 'XLim', 'PostSet', @(src,evt) test(src, evt, a2));
This example is on one figure. However, you can do the same with two figures.

추가 답변 (1개)

Titus Edelhofer
Titus Edelhofer 2015년 2월 19일
Hi,
using linkaxes (or the more general linkprop) this will not work, because only the same property can be linked. What should work is to use a zoom object:
x=1:5;
figure;
plot(x);
a1 = gca;
figure;
p2 = plot(x+1);
a2 = gca;
h = zoom(1);
h.ActionPostCallback = @(hFig, hAx) set(a2, 'ylim', get(a1, 'xlim'));
And vice versa for figure 2 ...
Titus

카테고리

Help CenterFile Exchange에서 Visual Exploration에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by