필터 지우기
필터 지우기

A question about linkaxes options

조회 수: 9 (최근 30일)
Razvan
Razvan 2012년 10월 10일
Hi all,
I would like to link all the x axes but only a subgroup of the y axes in a figure. For example is I have 3 axes (ax(1:3)), I want all the panels to show the same x domain but only the first 2 to rescale the y axis in a similar way.
If I try this:
linkaxes(ax, 'x');
linkaxes(ax(1:2), 'y');
the second linkaxes cancels the first one, so I end up with only 2 panels linked.
Is this type of link possible?
Thanks,
Razvan
EDIT:
Here is an example to make the question more clear:
x = 1:1000;
figure
ax(1) = subplot(311);
plot(x .* sin(x));
xlim([51 100])
ax(2) = subplot(312);
plot(3 .* x .* sin(x));
xlim([51 100])
ax(3) = subplot(313);
plot(sin(x));
xlim([51 100])
linkaxes(ax, 'x');
pan xon
% linkprop(ax(1:2), 'Ylim');
If I pan the lower panel the upper panels rescale and look nice. If I uncomment the linkprop line then the top panels are "y-axis linked" but they don't rescale anymore when I pan the lower panel. (Note: the panel that you use to pan doesn't rescale in any case)
So the question is: How can I use linkprop to link the ax(1:2) y axes but to keep them rescalling while I pan along x (in other words to keep 'ylimmode' 'auto')?

채택된 답변

Pedro Villena
Pedro Villena 2012년 10월 11일
편집: Pedro Villena 2012년 11월 8일
MyScript.m
%%Initial Data
x = 1:1000;
y1=x.*sin(x);
y2=3*x.*sin(x);
y3=sin(x);
rangeX=[51 100];
%%Plot Figure
h.fig = figure;
h.ax(1) = subplot(3,1,1);
plot(y1,'Parent',h.ax(1));
h.ax(2) = subplot(3,1,2);
plot(y2,'Parent',h.ax(2));
h.ax(3) = subplot(3,1,3);
plot(y3,'Parent',h.ax(3));
h.link(1) = linkprop(h.ax,'XLim');
h.link(2) = linkprop([h.ax(1) h.ax(2)],'YLim');
xlim(rangeX);
%%Pan Handle
h.pan = pan;
guidata(h.fig,h.ax);
setAllowAxesPan(h.pan,h.ax(1),false);
setAxesPanMotion(h.pan,h.ax(2),'horizontal');
setAllowAxesPan(h.pan,h.ax(3),false);
set(h.pan,'ActionPostCallback',@mypostcallback);
set(h.pan,'Enable','on');
mypostcallback.m
function mypostcallback(obj,evd)
% Extract Data
h_ax = guidata(obj);
y2 = get(findobj(h_ax(2),'Type','Line'),'Ydata');
% Get Range
rangeX = round(get(evd.Axes,'XLim'));
rangeY = [min(y2(rangeX(1):rangeX(2))) max(y2(rangeX(1):rangeX(2)))];
set(h_ax(2),'Ylim',rangeY);
  댓글 수: 1
Razvan
Razvan 2012년 10월 11일
편집: Razvan 2012년 10월 13일
Doesn't work...
Pan to x ~ 500 and you'll see that the middle axes don't rescale properly...
Thanks for your effort though. Any other suggestions? Anyone?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2012년 10월 10일
Try with linkprop() and link XLim and YLim as needed
  댓글 수: 1
Razvan
Razvan 2012년 10월 10일
편집: Razvan 2012년 10월 10일
Great! Thanks! One more thing... Before I link the ylim properties the y axes rescale such that all the plots look nice, when I pan along the x axis. After linking them I think all the axes take the ylim property of the first object, so the other plots can look ugly if the plots extend outside the y domain of the first plot. Can I keep this autorescalling property for the y axis but to rescale all the plots in a similar way?
I think I should do something like
set(ax(1), 'ylimmode', 'auto')
but it doesn't seem to work after I link the axes...

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by