A question about linkaxes options

8 ビュー (過去 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 Center および File ExchangeGeographic Plots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by