def GetTickTexts(ticks):
    """ GetTickTexts(ticks)
    
    Get tick labels of maximally 9 characters (plus sign char). 
    
    All ticks will be formatted in the same manner, and with the same number
    of decimals. In exponential notation, the exponent is written with as
    less characters as possible, leaving more chars for the decimals.
    
    The algorithm is to first test for each tick the number of characters
    before the dot, the number of decimals, and the number of chars for
    the exponent. Then the ticks are formatted only without exponent if
    the first two chars (plus one for the dot) are less than 9.    
    
    Examples are:
    xx.yyyyyy
    xxxxxxx.y
    x.yyyye+z
    x.yye+zzz
    
    """
    
    # For padding/unpadding exponent notation
    def exp_pad(s, i=1):
        return s.lstrip('0').rjust(i,'0')
    
    
    # Round 1: determine amount of chars before dot, after dot, in exp
    minChars1, maxChars1 = 99999, 0
    maxChars2 = 0
    maxChars3 = 0
    for tick in ticks:
        
        # Make abs, our goal is to format the ticks such that without
        # the sign char, the string is smaller than 9 chars.
        tick = abs(tick)
        
        # Format with exponential notation and get exponent
        t = '%1.0e' % tick
        i = t.find('e')
        expPart = t[i+2:]
        
        # Get number of chars before dot
        chars1 = int(expPart)+1
        maxChars1 = max(maxChars1, chars1)
        minChars1 = min(minChars1, chars1)
        
        # Get number of chars in exponent
        maxChars3 = max(maxChars3, len(exp_pad(expPart)))
        
        # Get number of chars after the dot
        t = '%1.7f' % tick
        i = t.find('.')
        decPart = t[i+1:]
        maxChars2 = max(maxChars2, len(decPart.rstrip('0')))
    
    # Round 2: Create actual texts
    ticks2 = []
    if maxChars1 + maxChars2 + 1 <= 9:
        # This one is easy
        
        chars2 = maxChars2
        f = '%%1.%if' % chars2
        for tick in ticks:
            # Format tick and store
            if tick == -0: tick = 0
            ticks2.append( f % tick )
    
    elif maxChars1 < 9:        
        # Do the best we can
        
        chars2 = 9 - (maxChars1+1)
        f = '%%1.%if' % chars2
        for tick in ticks:
            # Format tick and store
            if tick == -0: tick = 0
            ticks2.append( f % tick )
    
    else:
        # Exponential notation
        chars2 = 9 - (4+maxChars3)  # 0.xxxe+yy
        f = '%%1.%ie' % chars2
        for tick in ticks:
            # Format tick
            if tick == -0: tick = 0
            t = f % tick
            # Remove zeros in exp
            i = t.find('e')
            t = t[:i+2] + exp_pad(t[i+2:], maxChars3)
            # Store
            ticks2.append(t)
    
    # Done
    return ticks2