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 Answer 1
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.
-
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– bassngo2010年08月03日 00:12:51 +00:00Commented Aug 3, 2010 at 0:12
-
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– karpathy2010年08月03日 00:22:34 +00:00Commented Aug 3, 2010 at 0:22
-
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 +1karpathy– karpathy2010年08月03日 00:25:34 +00:00Commented Aug 3, 2010 at 0:25
-
why do you have to divide by M+1?bassngo– bassngo2010年08月03日 00:48:44 +00:00Commented Aug 3, 2010 at 0:48
-
no :) you divide by M, and then at the end add 1 :) since that's where you want it centered.karpathy– karpathy2010年08月03日 04:53:30 +00:00Commented Aug 3, 2010 at 4:53