Re: rounding a number
- From: "James Parsly" <japarsly@xxxxxxxxxxxxxx>
- Date: Mon, 27 Nov 2006 16:59:47 -0500
Adding my 2-cents, I generally want to come up with a min, max and step (for
labels or gridlines)
I make the min and max multiples of the step, and pick the step so that the
number of steps falls within
a specified range, usually between 10 and 20. For integers, I like to use
steps like 1,2,5,10,20,25,50,
Another thing to consider is whether your scale should simply match the data
or whether it should be extended
to a more "natrural" range. For example, I do a lot of plots involving
reservoir information which includes
headwater elevations and dam releases. For the releases, we generally want
the scale to start at 0 regardless
of whether the data happens to include a 0. For the elevations, we will
often have a default scale setting
that includes the normal range of data, and only override the scale the data
to be plotted falls outside the normal
range. If you make a big pile of plots and want to compare them to each
other, its generally a lot easier if
they all are drawn with the same scale.
"glen herrmannsfeldt" <gah@xxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:ekfg4d$f8q$1@xxxxxxxxxxxxxxxxxxx
arman <previah@xxxxxxxxx> wrote:
How do you round some arbitrary number to the 10 multiplier? I need to
make a graph. The y-axis is dependent on the result of the computation.
If the maximum value of the y-axis, say for example 278, then I want
the y-axis to have a maximum of 300, or if it 2435 then I want the
maximum of 2500. So, basically it has to convert an arbitrary number
into some integer number that can be divided by 10.
You can start with rounding log10(), and then a loop to find
the appropriate multiple. Some allow multiplies of only 2 and 5,
others allow 2, 4, 5, 8, and possibly 3. (If plotting on
10 line per inch graph paper, 2 and 5 are best.)
Good axis label calculation isn't easy, especially if you allow
for graphs with the left or bottom coordinate non-zero.
Ones I knew did something like subtract the lower value from
the upper value, divide by the axis length, then take log10()
and round down. Next loop over the possible multipliers like
2, 4, 5, 8, 10, to see which one works.
Next, correct for the possibility that with the just determined
scale factor, the origin might not be on a grid line, requiring
recomputing the multiplier. Round the lower bound down and
the upper bound up to the appropriate multiple of as determined,
and test that the length is still right. If not, change the
multiplier and recompute the limits.
-- glen
.
- References:
- rounding a number
- From: arman
- Re: rounding a number
- From: glen herrmannsfeldt
- rounding a number
- Prev by Date: Re: ARRAY EQUATION VS FORALL
- Next by Date: Re: random numbers in fortran
- Previous by thread: Re: rounding a number
- Next by thread: Re: rounding a number
- Index(es):
Relevant Pages
|