LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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

Reply
 
Search this Thread
Old 09-03-2005, 06:48 AM   #1
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,544
Blog Entries: 4

Rep: Reputation: 56
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
 
Old 09-03-2005, 09:42 AM   #2
addy86
Member
 
Registered: Nov 2004
Location: Germany
Distribution: Debian Testing
Posts: 332

Rep: Reputation: 31
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 ...
 
Old 09-03-2005, 01:41 PM   #3
mschutte
Member
 
Registered: Jan 2005
Location: Innsbruck, Austria
Distribution: Debian GNU/Linux Lenny
Posts: 68

Rep: Reputation: 15
[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]
 
Old 09-03-2005, 10:33 PM   #4
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,544
Blog Entries: 4

Original Poster
Rep: Reputation: 56
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
stuck again (noob bash math question) babag Programming 6 04-25-2005 01:27 AM
math/probubility/gambling question true_atlantis Programming 12 10-16-2004 04:21 PM
Math question... counting theory Dark_Helmet General 6 08-30-2004 03:27 PM
Documents to learn C language and Perl/python satimis Programming 5 03-19-2004 10:20 AM
Is Python a good language to learn for a newbie to programming? prophet621 Programming 2 05-19-2003 03:48 PM


All times are GMT -5. The time now is 10:25 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration