graph problems - python is the language but math is the question
I've got a function that returns a value, a percentage to be exact. This percentage is almost always going to be between 80-85, so to graph that with an X axis of 0 - 100 will look boring, it'll be mostly a straight line. I want to magnify it so the X axis will only display a range of say 75-90 so as to magnify the results and make it look more interesting. I'll be calling the function every second and the graph will be dynamic, I'm making a desklet. Basically, I want to take a range of 0-100, make it so an internal range of 75-90 is equal to 0-100, then graph that.
I know what I want to do and if I was drawing the graph on paper it'd be a non-issue but I'm drawing a blank as to how I can work this out. I can't think of a better way to explain it so I hope somebody understood. Any suggestions on the math behind this would be appreciated, I can do the code to draw the graph no worries. Thanks :) |
Say x is the value which is mostly between 80 and 85; 75 is the beginning of the scale, 90 the end of it; then
x' := ( x - 75 ) * ( 100 / ( 90 - 75 ) ) is the value of x scaled accordingly. Note: Only in case you don't know: Dividing two integers (as above) results in an integer in Python (afaik), so instead write ... 100.0 ... |
[A bit off-topic]
To the last sentence of addy86's posting: Yes, Python currently does integer divisions per default, if both operands are integers. But it is a good practise to run python as follows: $ python -Qnew or to include the following line at the beginning of your own scripts: from __future__ import division This is because Python 4.0 will change this default and will do floating point divisions everytime. I just wanted to point that out. [/A bit off-topic] |
Quote:
mschutte: Thanks for pointing that out. I did actually know that, I've played with it before in a different script but it seems easier to just make sure I'm using floats in division. Its worked for me this far and while I'll probably have forgotten somewhere along the line and made a mistake, someone will send me abusive email when Python 4.0 is released and I'll know to fix it ;) |
All times are GMT -5. The time now is 08:00 PM. |