[comp.sys.ibm.pc] Selection of Axes scale, intervals for a set of points

amlovell@phoenix.Princeton.EDU (Anthony M Lovell) (04/26/88)

I looked in the library till my head hurt (I'm no expert at library
use), so I'm going to ask if any netter can refer me to (or supply) a
good algorithm for determining "nice" ranges and intervals for 
plotting a set of points.  I can have the points "on hand", so I'll know
the max and min for both x and y components.  Then...
it's sorta tricky to have the computer apply the same hazy decisions a
person would use in determining an appealing set of axes for the graph.
Can anyone help me and keep me from reinventing the wheel?

-- 
amlovell@phoenix.princeton.edu     ...since 1963.

disclaimer:
These are MY opinions.  You only WISH they were yours.

usenet@dandelion.CI.COM (News Administrator) (04/27/88)

Rules I have used since my early CalComp days (late 1950's):
From: jim@alamode.ci.com (Jim Hurt)
Path: alamode!jim

Rule I.  Delta (the difference between the data values at two
consecutive major tic marks) will be some power of ten times 1, 2, or 5. 

Rule II.  The first tic mark will be at some integer times Delta. 

Outline of the Algorithm:

1.  Using xmin and xmax (the range of values for the axis) and a
preliminary shot at the number of intervals between major tic marks N,
compute the smallest possible delta:

	delta := (xmax - xmin) / float(N)

2.  Scale this delta by a power of ten until delta1 is between 1.0 and
10.0:

	1.0 .le. (delta1 := delta * 10.0**k) .lt. 10.0

Remember this value for k for later use.

3.  Select the smallest from a table of "nice" deltas that is not larger
than this delta1.  I use

	nice deltas := [1.0, 2.0, 5.0, 10.0]

but you can use a different set.  Just be sure 1.0 and 10.0 are both in
your set.

4.  Convert back to the original scale:

	delta := (nice delta) * 10.0**(-k)

where the k is the same value used in step 2 above.

5.  Compute the largest integer M such that:

	(leftEdge := M * delta) .le. xmin

Caution: this M may be a negative integer.

6.  Test if original data range will still be on the graph:

	Is (leftEdge + N * delta) .ge. xmax

If not, then at your option,
    a. increase the number of tic marks N by one and repeat from step 6,
or
    b. move up to the next larger "nice" delta and repeat the test from
step 5.

I prefer the second option.
========================================================================
New Englanders are a very tolerant people, but there are some things
that they will not tolerate.  For example, the shoot people who write
about a beautiful spring.  Mark Twain.
========================================================================
jim@dandelion.CI.UUCP

adh@anumb.UUCP (a.d.hay) (04/29/88)

In article <2656@phoenix.Princeton.EDU> amlovell@phoenix.Princeton.EDU (Anthony M Lovell) writes:
>I looked in the library till my head hurt (I'm no expert at library
>use), so I'm going to ask if any netter can refer me to (or supply) a
>good algorithm for determining "nice" ranges and intervals for 
>plotting a set of points.  I can have the points "on hand", so I'll know
>the max and min for both x and y components.  Then...
>it's sorta tricky to have the computer apply the same hazy decisions a
>person would use in determining an appealing set of axes for the graph.
>Can anyone help me and keep me from reinventing the wheel?
>
how 'bout using integer division on the min & max?
divide by 5 or 10 (for example) then round away from the data range.
>-- 
>amlovell@phoenix.princeton.edu     ...since 1963.
>
>disclaimer:
>These are MY opinions.  You only WISH they were yours.
no, i don't, either!

l
i
n
e

s
t
u
f
f
i
n
g

-- 
Andrew Hay		+------------------------------------------------------+
AT&T-BL Ward Hill MA	|	"Don`t try to out-wierd ME, three-eyes!"       |
ihnp4!mvuxq!adh		+------------------------------------------------------+