开发者

How to scale down the y-axis in matplotlib/python?

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-开发者_StackOverflow中文版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.


You can just do a simple linear transformation, for all y's:

ynew= 2*(y-ymin)/(ymax-ymin)

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜