1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Scaling node coordinates to a fixed graph size

  1. Jan 12, 2009 #1
    Hi, suppose i have various graphs which each have many nodes. In one graph the nodes x and y values may be within the range 0-1000, in another the x values may range from 100-500 and the y values from 300-800. Basically, the ranges always vary and there is no consistency.

    I need a way to scale the values of the x and y coordinates such that they fit inside a fixed graph size (say 500 by 500) such that the graph retains in basic layout and relative distances between nodes.

    Probably not that hard a question, i just cant figure it out :). Thx for any help.
  2. jcsd
  3. Jan 12, 2009 #2


    User Avatar
    Science Advisor

    If your graph x and y range from 0 to A and you want it to fit inside 0 to B, multiply all coordinates by B/A.

    For example, if you x and y coordinates are always between 0 and 1000 and you want it to fit inside 0 to 500 multiply all coordinates by 500/1000= 1/2. So, for example, the point (900,800) would change to (450, 400).
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook