views:

104

answers:

1

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.

+1  A: 

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.

karpathy
Would this work if my values were a bunch of deltas. So I wanted the initial y_value to be centered at y=1 and the rest of the values between y=0 and y=2 depending on their delta to the initial y_value.
bassngo
But what if ymin is off more from yinit than ymax is? Would you want to "squish" the top and bottom differently to make sure it definitely all lies in [0,2] ? That's probably not what you are looking for.
karpathy
I think you want to do something like this:M= max(abs(yinit-ymin), abs(yinit-ymax))the for all y's:ynew= (y-yinit)/M +1
karpathy
why do you have to divide by M+1?
bassngo
no :) you divide by M, and then at the end add 1 :) since that's where you want it centered.
karpathy