A question about linkaxes options
8 ビュー (過去 30 日間)
古いコメントを表示
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')?
0 件のコメント
採用された回答
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 件)
参考
カテゴリ
Help Center および File Exchange で Geographic Plots についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!