本文介绍了设置xlim后如何从屏幕上显示的数据自动设置ylim的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
比如我设置了 xlim 后,ylim 比屏幕上显示的数据点范围更宽.当然,我可以手动选择一个范围并进行设置,但是我希望它是自动完成的.
For example, after I set xlim, the ylim is wider than the range of data points shown on the screen. Of course, I can manually pick a range and set it, but I would prefer if it is done automatically.
或者至少我们如何确定屏幕上显示的数据点的y范围?
Or, at least, how can we determine y-range of data points shown on screen?
在我设置 xlim 后立即绘图:
plot right after I set xlim:
我手动设置 ylim 后的绘图:
plot after I manually set ylim:
推荐答案这种方法适用于 y(x) 是非线性的.给定要绘制的数组 x 和 y:
This approach will work in case y(x) is non-linear. Given the arrays x and y that you want to plot:
lims = gca().get_xlim() i = np.where( (x > lims[0]) & (x < lims[1]) )[0] gca().set_ylim( y[i].min(), y[i].max() ) show()更多推荐
设置xlim后如何从屏幕上显示的数据自动设置ylim
发布评论