设置xlim后如何从屏幕上显示的数据自动设置ylim [英] How to automatically set ylim from data shown on the screen after setting xlim

查看:35
本文介绍了设置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) 是非线性的.给定要绘制的数组 xy:

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆