如何在matplotlib/python中缩小y轴?
这更像是一个数学问题,而不是 matplotlib 问题,但如果有一种方法可以专门在 matplotlib 中执行此操作,那就太好了。
我有一组具有最大 y 值和最小 y 值的点,其差异可能在几百到几千之间。
我试图在 y 轴上以非常小的比例绘制这些点(可能是 2 个单位的跨度)。
例如,我有点 (10, 20) (11, 123) (12, 77) (13, 124),我想将它们绘制在 0-2 的 y 值之间。我该如何缩小规模?无论是数学方式还是内置的 matplotlib 方式。
This is more of a math question than a matplotlib question but if there is a way to do this specifically in matplotlib that would be great.
I have a set of points with the max-y-value and the min-y-value can have a difference anywhere from a few hundred to a few thousand.
I am trying to plot these points in a very small scale on the y-axis (maybe a span of 2 units).
For example, I have the points (10, 20) (11, 123) (12, 77) (13, 124) and I want to plot them inbetween the y_values of 0-2. How would I scale this down? Either mathematically or a built-in matplotlib way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以对所有 y 进行简单的线性变换:
分数 (y-ymin)/(ymax-ymin) 首先给出 y 坐标在您感兴趣的范围内的百分比,然后从范围中获取它0-1进入范围0-2,只需乘以2即可。
You can just do a simple linear transformation, for all y's:
The fraction (y-ymin)/(ymax-ymin) first gives you the percentage of the y coordinate in the range you are interested in, and then to get it from range 0-1 into range 0-2, you just multiply by 2.