A question about linkaxes options
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Pedro Villena
am 11 Okt. 2012
Bearbeitet: Pedro Villena
am 8 Nov. 2012
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 Kommentar
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Geographic Plots finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!