0

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

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.

Sign up to request clarification or add additional context in comments.

5 Comments

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.
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.
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
why do you have to divide by M+1?
no :) you divide by M, and then at the end add 1 :) since that's where you want it centered.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.