How can I keep automatical adjustment of y-axis limits when manually zooming/using pan tool?
17 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Richard
2015-3-5
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Exploration 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!