Borrar filtros
Borrar filtros

A question about linkaxes options

9 visualizaciones (últimos 30 días)
Razvan
Razvan el 10 de Oct. de 2012
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')?

Respuesta aceptada

Pedro Villena
Pedro Villena el 11 de Oct. de 2012
Editada: Pedro Villena el 8 de Nov. de 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 comentario
Razvan
Razvan el 11 de Oct. de 2012
Editada: Razvan el 13 de Oct. de 2012
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?

Iniciar sesión para comentar.

Más respuestas (1)

Walter Roberson
Walter Roberson el 10 de Oct. de 2012
Try with linkprop() and link XLim and YLim as needed
  1 comentario
Razvan
Razvan el 10 de Oct. de 2012
Editada: Razvan el 10 de Oct. de 2012
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...

Iniciar sesión para comentar.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by