Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!necntc!dandelion!usenet From: usenet@dandelion.CI.COM (News Administrator) Newsgroups: comp.sys.ibm.pc Subject: Re: Selection of Axes scale, intervals for a set of points Message-ID: <4336@dandelion.CI.COM> Date: 27 Apr 88 13:58:42 GMT References: <2656@phoenix.Princeton.EDU> Reply-To: jim@alamode.UUCP (Jim Hurt) Organization: Cognition, Inc., Billerica, MA Lines: 60 Keywords: need an algorithm 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