How can I keep automatical adjustment of y-axis limits when manually zooming/using pan tool?

17 views (last 30 days)
Hello,
Is there a possibility to keep the 'ylimmode' axes property set to 'auto' when manually zooming in/out or moving the graph in x-direction with the pan tool?
I defined a plot with specified limits of the x-axis and the 'ylimmode' property set to 'auto' (which is set by default anyway). E.g. like:
F = figure;
x = linspace(0,10*pi,1000);
signal = sin(t) + 0.07*randn(size(x));
h = plot(x,signal,'-x');
set(gca,'xlim', [2 3],'ylimmode','auto')
Whenever I scroll through the plot in x-direction using the pan tool in the property editor, 'ylimmode' property is set to 'manual' automatically. However, I want the limits of the y-axis to adjust automatically to the data when moving the graph from left to right. Is there a way to keep the 'ylimmode' property set to 'auto'?
Am looking forward for any comments. Thanks, Alex

Answers (1)

Richard
Richard on 5 Mar 2015
I was looking to have the y-axis limits reset while panning so that a time series curve was always within the plot window. Setting a callback from the pan event seems to work.
Creat the plot then set a callback on pan:
hpan = pan;
set(hpan,'Motion','horizontal','Enable','on');
set(hpan,'ActionPostCallback',@mypostcallback);
Now set YLimMode in the call back function:
function mypostcallback(obj,evd)
h = findobj(obj,'Type','axes');
set(h(:),'YLimMode','auto');
end
I wanted this to work for all subplots in the figure (obj) so used findobj. There is probably a better way to get the axes handles from the heirarchy but this seems to work.

Categories

Find more on Data Exploration in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!