设置xlim后如何从屏幕上显示的数据自动设置ylim

编程入门 行业动态 更新时间:2024-10-27 01:29:05
本文介绍了设置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

本文发布于:2023-07-18 08:24:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1142811.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据   屏幕上   xlim   ylim

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!