My approach is pretty much as others have described:
1. Get min and max based on data
2. Try a step size.
For integer data I try 1,2,5,10,20,50,... Round min down to next lower
multiple of step size.
Round max up to next higher multiple of step size.
3. Determine number of tick mark labels that the step size would require. If
too many (>10), back to step 2
to try the next step size.
One other thing to consider.
Do you want to have a default range? We often plot water releases from
dams. We make the default range
of data go from 0 to turbine discharge capaciity, but will increase the
range if there is plot data outside the default
(when the dam is spilling water). Having a default range makes it easier to
compare graphs.
"glen herrmannsfeldt"
ugcs.caltech.edu> wrote in message
news:nZGdnQcWOaOeAU3VnZ2dnUVZ_qrinZ2d@comcast.com...
> Robert Singer wrote:
>
>> First, Let me describe what I'm interested in; most of you have used
>> excel or some similar program; when you put an array of data in it and
>> plot a graph/chart (x-y type), he will automatically determine the
>> upper and lower limit of the graph.
> (snip)
>
>> Okey, the first step is to determine xmin, xmax and the same for y,
>> for the given array. That is not a problem.
>> As far as I know fortran has no intristics for rounding numbers, so
>> that would be one part of the problem.
>
> X and Y are separate, so just consider one. This is based on
> one I have used and modified over the years:
>
> You need Xmin, Xmax, and the desired axis length: Axlen
> (number of intermediate tick marks.) Compute the value
> for the low end (TL) and tick increment (TX).
>
> real table(14)
> ! available scale factors, with power of 10 removed
> ! up to 20 allows for some roundoff that might occur
> ! on 10th inch graph paper, you might want /1, 2, 5, 10, 20/
> data table/1.,1.2,1.5,2.,2.4,3.,4.,5.,6.,8.,10.,12.,15.,20./
> F=0.01
> if(Xmin<0) F=0.99 ! round in the right direction
> TX=(Xmax-Xmin)/Axlen ! first approximation to scale factor
> if(TX<=0) TX=abs(2*TX/Axlen)+1 ! reasonable results if no data range
> P=10.**int(log10(TX)) ! largest power of 10 less than TX
> TX=TX/P-0.01 ! divide by P and reduce slightly
> ! TX should be between about 1 and 10
> DO I=1,size(table)
> if(table(I).ge.TX) exit ! potential nice scale factor
> ENDDO
> DO I=I,size(table)
> TX=table(I)*P ! restore power of 10 removed earlier
> TL=TX*floor(Xmin/TX+F) ! compute new lower limit based on scale
> T=TL+(Axlen+0.01)*TX ! compute upper limit from lower limit and scale
> if(T.gt.Xmax) exit ! it works!
> TL=P*floor(Xmin/P+F) ! it doesn't, recompute lower limit
> T=TL+(Axlen+0.01)*TX ! and upper limit
> if(T.gt.Xmax) exit ! and test again
> ENDDO ! try the next largest scale constant
> ! because of the rounding, the result may be less centered than needed
> TL=TL-aint((Axlen+(TL-Xmax)/TX)/2.)*TX
> if(Xmin*TL.lt.0) TL=0 ! don't cross zero if the data doesn't
>
> The loop allows successive attempts such that the lower limit
> is not greater than Xmin, the upper limit is not lower than Xmax,
> zero is on a tick if included or near the data limits.
> The last correction is needed as the scale factor increases
> may result in the graph being way off center.
>
>
> -- glen
>