'Formats the value `x` based on the size of the axis range `d`.'

def pprint_val(self, x, d):

    if ((abs(x) < 10000.0) and (x == int(x))):
        return (u'%d' % x)
    if (d < 0.01):
        fmt = u'%1.3e'
    elif (d < 0.1):
        fmt = u'%1.3f'
    elif (d > 100000.0):
        fmt = u'%1.1e'
    elif (d > 10):
        fmt = u'%1.1f'
    elif (d > 1):
        fmt = u'%1.2f'
    else:
        fmt = u'%1.3f'
    s = (fmt % x)
    tup = s.split(u'e')
    if (len(tup) == 2):
        mantissa = tup[0].rstrip(u'0').rstrip(u'.')
        sign = tup[1][0].replace(u'+', u'')
        exponent = tup[1][1:].lstrip(u'0')
        s = (u'%se%s%s' % (mantissa, sign, exponent))
    else:
        s = s.rstrip(u'0').rstrip(u'.')
    return s
