Reasonable Contour Levels

By Hal Canary, 2012-04-23 12:00:00 (link)

import math
def generateContours(min_value, max_val, target):
    value_range = max_val - min_value
    x = int(round(3 * math.log10(value_range / target)))
    if x % 3 == 1:
        x = 2.5 * math.pow(10,math.floor(x / 3))
    elif x % 3 == 2:
        x = 5.0 * math.pow(10,math.floor(x / 3))
    else:
        x = math.pow(10, x / 3)
    low = math.ceil(min_value / x) * x
    return [low + (x * i)
        for i in xrange(1+int(value_range / x))]

(back)