Set x-axis limits using xlim AND autoscale y-axis

109 ビュー (過去 30 日間)
Paddy
Paddy 2011 年 6 月 10 日
コメント済み: chlor thanks 2016 年 7 月 11 日
I would like to do something incredibly simple. On a plot I would like to be able to zoom in to a certain portion by setting the x-axis using xlim, and have the y-axis autoscale to the min/max values in the NEW AXES rather than the whole dataseries. This is currently what happens if I use xlim([x1 x2]) then e.g. axis 'auto y'. Using axis tight resets both x and y-limits to show the entire dataseries.
I should point out I am plotting a waveform object (structure), not just two vectors, so can't just plot the relevant part of the data by doing something like plot(x(index1:index2),y(index1:index2))
I feel like this should be pretty simple, but I can't work it out, other than manually setting the y-axis limits. Any suggestions?
Thanks for your help!
  1 件のコメント
Jan
Jan 2011 年 6 月 10 日
I do not understand the question. What do you want to achieve for the y-limits?

サインインしてコメントする。

回答 (2 件)

John
John 2014 年 8 月 17 日
編集済み: John 2014 年 8 月 17 日
I understand the problem. After calling:
axis tight
both axis are reset. If you wanted to set your xlim and then rescale your y-axis automatically, the previous command will not work. Also, if you try to set the ylim parameters to inf and -inf, which normally autoscales, you get the same result
ylim([-inf, inf])
The limits are set based on the entirety of the data set, not just what's viewable in your new xlim window.
THE SOLUTION : After setting xlim([xmin,xmax]), you can autoscale the y-axis by:
axis 'auto y'
Finally, if you simply limit the range of data in your original plot command, you will not have this problem.
  1 件のコメント
chlor thanks
chlor thanks 2016 年 7 月 11 日
Awesome solution for my problem. Thank you!

サインインしてコメントする。


Matt Fig
Matt Fig 2011 年 6 月 10 日
Calling:
axis tight
Does reset the axes limits to the range of the data, as documented. So why is it that you are calling this after you set the axes limits to the disired range? I.e., what are you trying to accomplish by calling the AXIS function, if you already have the desired range?

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by