def define_tick(ticks, tickbeg, tickend, tickd, mtick, xbeg, xend, ns, d, axislen, format, extend=False):
    if (ticks is None):
        if (tickd is None):
            tick_interval = nice(((xend - xbeg) / 5.0))
            if (tick_interval == 0):
                tick_interval = 10000000000.0
        else:
            tick_interval = float(tickd)
        if (tickbeg is None):
            tick_beg = nice(xbeg)
            base = 0.5
            nb = 0
            if (tick_interval > 0):
                while ((nb <= 10) and (tick_beg > (xbeg + tick_interval))):
                    base = (base / 10.0)
                    tick_beg = nice(xbeg, base)
                    nb = (nb + 1)
            else:
                while ((nb <= 10) and (tick_beg < (xbeg + tick_interval))):
                    base = (base / 10.0)
                    tick_beg = nice(xbeg, base)
                    nb = (nb + 1)
        else:
            tick_beg = float(tickbeg)
        if (tickend is None):
            tick_end = (tick_beg + ((round(((xend - xbeg) / tick_interval)) + 2) * tick_interval))
            if (tick_interval > 0):
                while (tick_end < xend):
                    tick_end = (tick_end + abs(tick_interval))
            else:
                while (tick_end > xend):
                    tick_end = (tick_end - abs(tick_interval))
        else:
            tick_end = float(tickend)
        tick = np.arange(tick_beg, (tick_end + (0.1 * abs(tick_interval))), tick_interval)
        minor_tick_interval = (tick_interval / (mtick + 1.0))
        minor_tick = np.arange(tick_beg, (tick_end + (0.1 * abs(minor_tick_interval))), minor_tick_interval)
        if (not extend):
            if (d > 0):
                tick = np.asarray([i for i in tick if ((i >= xbeg) and (i <= xend))])
                minor_tick = np.asarray([i for i in minor_tick if ((i >= xbeg) and (i <= xend) and (not (i in tick)))])
            if (d < 0):
                tick = np.asarray([i for i in tick if ((i <= xbeg) and (i >= xend))])
                minor_tick = np.asarray([i for i in minor_tick if ((i <= xbeg) and (i >= xend) and (not (i in tick)))])
        if (ns == 1):
            tick_location = np.asarray([0.5])
            ntick = 1
        else:
            tick_location = [((((i - xbeg) + (0.5 * d)) / ((ns - 1) * d)) * axislen) for i in tick]
            minor_tick_location = [((((i - xbeg) + (0.5 * d)) / ((ns - 1) * d)) * axislen) for i in minor_tick]
            t = tick_location
        tl = []
        tick_label = []
        for i in range(0, len(tick)):
            if (extend or ((not extend) and (tick_location[i] >= 0) and (tick_location[i] <= (axislen + 1e-10)))):
                tl.append(tick_location[i])
                if ((format == 'sci') or (format == 'plain')):
                    tick_label.append(('%f' % tick[i]).rstrip('0').rstrip('.'))
                else:
                    tick_label.append((format % tick[i]))
        tick_location = tl
    else:
        ticks = ticks[0].split(',')
        location = [0 for i in range(0, len(ticks))]
        label = ['' for i in range(0, len(ticks))]
        for i in range(0, len(ticks)):
            t = ticks[i].split(':')
            location[i] = (((float(t[0]) + (0.5 * d)) / ((ns - 1) * d)) * axislen)
            label[i] = t[1]
        yx = list(zip(location, label))
        yx.sort()
        tick_location = [location for (location, label) in yx]
        tick_label = [label for (location, label) in yx]
        if (mtick != 0):
            mtick = (mtick + 1)
            minor_tick_location = np.linspace(tick_location[0], tick_location[1], (mtick + 1))
            minor_tick_location = minor_tick_location[1:mtick]
            for i in range(1, (len(tick_location) - 1)):
                t = np.linspace(tick_location[i], tick_location[(i + 1)], (mtick + 1))
                minor_tick_location = np.append(minor_tick_location, t[1:mtick])
        else:
            minor_tick_location = []
    return (tick_location, tick_label, minor_tick_location)
def define_tick(ticks, tickbeg, tickend, tickd, mtick, xbeg, xend, ns, d, axislen, format, extend=False):
    if (ticks is None):
        if (tickd is None):
            tick_interval = nice(((xend - xbeg) / 5.0))
            if (tick_interval == 0):
                tick_interval = 10000000000.0
        else:
            tick_interval = float(tickd)
        if (tickbeg is None):
            tick_beg = nice(xbeg)
            base = 0.5
            nb = 0
            if (tick_interval > 0):
                while ((nb <= 10) and (tick_beg > (xbeg + tick_interval))):
                    base = (base / 10.0)
                    tick_beg = nice(xbeg, base)
                    nb = (nb + 1)
            else:
                while ((nb <= 10) and (tick_beg < (xbeg + tick_interval))):
                    base = (base / 10.0)
                    tick_beg = nice(xbeg, base)
                    nb = (nb + 1)
        else:
            tick_beg = float(tickbeg)
        if (tickend is None):
            tick_end = (tick_beg + ((round(((xend - xbeg) / tick_interval)) + 2) * tick_interval))
            if (tick_interval > 0):
                while (tick_end < xend):
                    tick_end = (tick_end + abs(tick_interval))
            else:
                while (tick_end > xend):
                    tick_end = (tick_end - abs(tick_interval))
        else:
            tick_end = float(tickend)
        tick = np.arange(tick_beg, (tick_end + (0.1 * abs(tick_interval))), tick_interval)
        minor_tick_interval = (tick_interval / (mtick + 1.0))
        minor_tick = np.arange(tick_beg, (tick_end + (0.1 * abs(minor_tick_interval))), minor_tick_interval)
        if (not extend):
            if (d > 0):
                tick = np.asarray([i for i in tick if ((i >= xbeg) and (i <= xend))])
                minor_tick = np.asarray([i for i in minor_tick if ((i >= xbeg) and (i <= xend) and (not (i in tick)))])
            if (d < 0):
                tick = np.asarray([i for i in tick if ((i <= xbeg) and (i >= xend))])
                minor_tick = np.asarray([i for i in minor_tick if ((i <= xbeg) and (i >= xend) and (not (i in tick)))])
        if (ns == 1):
            tick_location = np.asarray([0.5])
            ntick = 1
        else:
            tick_location = [((((i - xbeg) + (0.5 * d)) / ((ns - 1) * d)) * axislen) for i in tick]
            minor_tick_location = [((((i - xbeg) + (0.5 * d)) / ((ns - 1) * d)) * axislen) for i in minor_tick]
            t = tick_location
        tl = []
        tick_label = []
        for i in range(0, len(tick)):
            if (extend or ((not extend) and (tick_location[i] >= 0) and (tick_location[i] <= (axislen + 1e-10)))):
                tl.append(tick_location[i])
                if ((format == 'sci') or (format == 'plain')):
                    tick_label.append(('%f' % tick[i]).rstrip('0').rstrip('.'))
                else:
                    tick_label.append((format % tick[i]))
        tick_location = tl
    else:
        ticks = ticks[0].split(',')
        location = [0 for i in range(0, len(ticks))]
        label = [ for i in range(0, len(ticks))]
        for i in range(0, len(ticks)):
            t = ticks[i].split(':')
            location[i] = (((float(t[0]) + (0.5 * d)) / ((ns - 1) * d)) * axislen)
            label[i] = t[1]
        yx = list(zip(location, label))
        yx.sort()
        tick_location = [location for (location, label) in yx]
        tick_label = [label for (location, label) in yx]
        if (mtick != 0):
            mtick = (mtick + 1)
            minor_tick_location = np.linspace(tick_location[0], tick_location[1], (mtick + 1))
            minor_tick_location = minor_tick_location[1:mtick]
            for i in range(1, (len(tick_location) - 1)):
                t = np.linspace(tick_location[i], tick_location[(i + 1)], (mtick + 1))
                minor_tick_location = np.append(minor_tick_location, t[1:mtick])
        else:
            minor_tick_location = []
    return (tick_location, tick_label, minor_tick_location)