Support LQ: Use code LQ3 and save \$3 on Domain Registration
 Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 LinuxQuestions.org graph problems - python is the language but math is the question
 Programming This forum is for all programming questions. The question does not have to be directly related to Linux and any language is fair game.

Notices

 09-03-2005, 07:48 AM #1 cs-cam Senior Member Contributing Member   Registered: May 2004 Location: Australia Distribution: Gentoo Posts: 3,544 Blog Entries: 4 Rep: 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
 09-03-2005, 10:42 AM #2 addy86 Member   Registered: Nov 2004 Location: Germany Distribution: Debian Testing Posts: 332 Rep: 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 ...
 09-03-2005, 02:41 PM #3 mschutte Member   Registered: Jan 2005 Location: Innsbruck, Austria Distribution: Debian GNU/Linux Lenny Posts: 68 Rep: [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]
09-03-2005, 11:33 PM   #4
cs-cam
Senior Member

Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,544
Blog Entries: 4

Original Poster
Rep:
Quote:
 Originally posted by addy86 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 ...
Thanks!! Worked great

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