Beispiel #1
0
    def partfunctions(self, min, max, extendmin, extendmax):
        try:
            logmm = math.log(max - min) / math.log(10)
        except ArithmeticError:
            raise RuntimeError(
                "partitioning failed due to empty or invalid axis range")
        if logmm < 0:  # correction for rounding towards zero of the int routine
            base = tick.rational((10, 1), power=int(logmm - 1))
        else:
            base = tick.rational((10, 1), power=int(logmm))
        ticks = map(tick.rational, self.variants[0])
        useticks = [t * base for t in ticks]

        return [
            lambda d=_partdata(min=min,
                               max=max,
                               extendmin=extendmin,
                               extendmax=extendmax,
                               sign=1,
                               tickindex=-1,
                               base=tick.rational(base)): self.partfunction(d),
            lambda d=_partdata(min=min,
                               max=max,
                               extendmin=extendmin,
                               extendmax=extendmax,
                               sign=-1,
                               tickindex=0,
                               base=tick.rational(base)): self.partfunction(d)
        ]
Beispiel #2
0
 def __init__(self, tickdists=None, labeldists=None, extendtick=0, extendlabel=None, epsilon=1e-10):
     if tickdists is None and labeldists is not None:
         self.ticklist = [tick.rational(labeldists[0])]
     else:
         self.ticklist = map(tick.rational, tickdists)
     if labeldists is None and tickdists is not None:
         self.labellist = [tick.rational(tickdists[0])]
     else:
         self.labellist = map(tick.rational, labeldists)
     self.extendtick = extendtick
     self.extendlabel = extendlabel
     self.epsilon = epsilon
Beispiel #3
0
 def __init__(self,
              tickdists=None,
              labeldists=None,
              extendtick=0,
              extendlabel=None,
              epsilon=1e-10):
     if tickdists is None and labeldists is not None:
         self.ticklist = [tick.rational(labeldists[0])]
     else:
         self.ticklist = map(tick.rational, tickdists)
     if labeldists is None and tickdists is not None:
         self.labellist = [tick.rational(tickdists[0])]
     else:
         self.labellist = map(tick.rational, labeldists)
     self.extendtick = extendtick
     self.extendlabel = extendlabel
     self.epsilon = epsilon
Beispiel #4
0
    def partfunctions(self, min, max, extendmin, extendmax):
        try:
            logmm = math.log(max - min) / math.log(10)
        except ArithmeticError:
            raise RuntimeError("partitioning failed due to empty or invalid axis range")
        if logmm < 0: # correction for rounding towards zero of the int routine
            base = tick.rational((10, 1), power=int(logmm-1))
        else:
            base = tick.rational((10, 1), power=int(logmm))
        ticks = map(tick.rational, self.variants[0])
        useticks = [t * base for t in ticks]

        return [lambda d=_partdata(min=min, max=max, extendmin=extendmin, extendmax=extendmax,
                                   sign=1, tickindex=-1, base=tick.rational(base)):
                       self.partfunction(d),
                lambda d=_partdata(min=min, max=max, extendmin=extendmin, extendmax=extendmax,
                                   sign=-1, tickindex=0, base=tick.rational(base)):
                       self.partfunction(d)]
Beispiel #5
0
 def __init__(self,
              smallestdecimal=tick.rational((1, 1000)),
              biggestdecimal=tick.rational((9999, 1)),
              equaldecision=1,
              decimal=decimal(),
              exponential=exponential()):
     """initializes the instance
     - smallestdecimal and biggestdecimal are the smallest and
       biggest decimal values, where the decimal texter should be used;
       they are rational instances; the sign of the tick is ignored here;
       a tick at zero is considered for the decimal texter as well
     - equaldecision (boolean) uses decimal texter or exponential texter
       globaly (set) or for each tick separately (unset)
     - decimal and exponential are texters to be used"""
     self.smallestdecimal = smallestdecimal
     self.biggestdecimal = biggestdecimal
     self.equaldecision = equaldecision
     self.decimal = decimal
     self.exponential = exponential
Beispiel #6
0
 def __init__(self,
              plus="",
              minus="-",
              mantissaexp=r"{{%s}\cdot10^{%s}}",
              skipexp0=r"{%s}",
              skipexp1=None,
              nomantissaexp=r"{10^{%s}}",
              minusnomantissaexp=r"{-10^{%s}}",
              mantissamin=tick.rational((1, 1)),
              mantissamax=tick.rational((10L, 1)),
Beispiel #7
0
 def layout(data):
     self.adjustaxis(data, data.ticks, graphtexrunner, errorname)
     self.texter.labels(data.ticks)
     if self.divisor:
         for t in data.ticks:
             t *= tick.rational(self.divisor)
     canvas = painter.axiscanvas(self.painter, graphtexrunner)
     if self.painter is not None:
         self.painter.paint(canvas, data, self, positioner)
     return canvas
Beispiel #8
0
 def layout(data):
     self.adjustaxis(data, data.ticks, graphtexrunner, errorname)
     self.texter.labels(data.ticks)
     if self.divisor:
         for t in data.ticks:
             t *= tick.rational(self.divisor)
     canvas = painter.axiscanvas(self.painter, graphtexrunner)
     if self.painter is not None:
         self.painter.paint(canvas, data, self, positioner)
     return canvas
Beispiel #9
0
 def autopartfunction(self, data):
     data.exponent *= self.autoexponent
     logarithmicparter = logarithmic(tickpreexps=[
         preexp([tick.rational((1, 1))], data.exponent), logarithmic.pre1exp
     ],
                                     extendtick=self.extendtick,
                                     extendlabel=self.extendlabel,
                                     epsilon=self.epsilon)
     return logarithmicparter.partfunctions(min=data.min,
                                            max=data.max,
                                            extendmin=data.extendmin,
                                            extendmax=data.extendmax)[0]()
Beispiel #10
0
 def getticks(self, min, max, preexp, ticklevel=None, labellevel=None):
     ticks = []
     minimin = 0
     maximax = 0
     for f in preexp.pres:
         thisticks = []
         imin = int(math.ceil(math.log(min / float(f)) /
                              math.log(preexp.exp) - 0.5 * self.epsilon))
         imax = int(math.floor(math.log(max / float(f)) /
                               math.log(preexp.exp) + 0.5 * self.epsilon))
         for i in range(imin, imax + 1):
             pos = f * tick.rational((preexp.exp, 1), power=i)
             thisticks.append(tick.tick((pos.num, pos.denom), ticklevel = ticklevel, labellevel = labellevel))
         ticks = tick.mergeticklists(ticks, thisticks)
     return ticks
Beispiel #11
0
 def partfunction(self, data):
     if data.sign == 1:
         if data.tickindex < len(self.variants) - 1:
             data.tickindex += 1
         else:
             data.tickindex = 0
             data.base.num *= 10
     else:
         if data.tickindex:
             data.tickindex -= 1
         else:
             data.tickindex = len(self.variants) - 1
             data.base.denom *= 10
     tickdists = [tick.rational(t) * data.base for t in self.variants[data.tickindex]]
     linearparter = linear(tickdists=tickdists, extendtick=self.extendtick, epsilon=self.epsilon)
     return linearparter.partfunctions(min=data.min, max=data.max, extendmin=data.extendmin, extendmax=data.extendmax)[0]()
Beispiel #12
0
 def getticks(self, min, max, preexp, ticklevel=None, labellevel=None):
     ticks = []
     minimin = 0
     maximax = 0
     for f in preexp.pres:
         thisticks = []
         imin = int(
             math.ceil(
                 math.log(min / float(f)) / math.log(preexp.exp) -
                 0.5 * self.epsilon))
         imax = int(
             math.floor(
                 math.log(max / float(f)) / math.log(preexp.exp) +
                 0.5 * self.epsilon))
         for i in range(imin, imax + 1):
             pos = f * tick.rational((preexp.exp, 1), power=i)
             thisticks.append(
                 tick.tick((pos.num, pos.denom),
                           ticklevel=ticklevel,
                           labellevel=labellevel))
         ticks = tick.mergeticklists(ticks, thisticks)
     return ticks
Beispiel #13
0
 def partfunction(self, data):
     if data.sign == 1:
         if data.tickindex < len(self.variants) - 1:
             data.tickindex += 1
         else:
             data.tickindex = 0
             data.base.num *= 10
     else:
         if data.tickindex:
             data.tickindex -= 1
         else:
             data.tickindex = len(self.variants) - 1
             data.base.denom *= 10
     tickdists = [
         tick.rational(t) * data.base for t in self.variants[data.tickindex]
     ]
     linearparter = linear(tickdists=tickdists,
                           extendtick=self.extendtick,
                           epsilon=self.epsilon)
     return linearparter.partfunctions(min=data.min,
                                       max=data.max,
                                       extendmin=data.extendmin,
                                       extendmax=data.extendmax)[0]()
Beispiel #14
0
class logarithmic(linear):
    """partitioner to create a single logarithmic parition"""

    # define some useful constants
    pre1exp = preexp([tick.rational((1, 1))], 10)
    pre125exp = preexp(
        [tick.rational((1, 1)),
         tick.rational((2, 1)),
         tick.rational((5, 1))], 10)
    pre1to9exp = preexp([tick.rational((x, 1)) for x in range(1, 10)], 10)

    #  ^- we always include 1 in order to get extendto(tick|label)level to work as expected

    def __init__(self,
                 tickpreexps=None,
                 labelpreexps=None,
                 extendtick=0,
                 extendlabel=None,
                 epsilon=1e-10):
        if tickpreexps is None and labelpreexps is not None:
            self.ticklist = [labelpreexps[0]]
        else:
            self.ticklist = tickpreexps

        if labelpreexps is None and tickpreexps is not None:
            self.labellist = [tickpreexps[0]]
        else:
            self.labellist = labelpreexps
        self.extendtick = extendtick
        self.extendlabel = extendlabel
        self.epsilon = epsilon

    def extendminmax(self, min, max, preexp, extendmin, extendmax):
        minpower = None
        maxpower = None
        for i in xrange(len(preexp.pres)):
            imin = int(
                math.floor(
                    math.log(min / float(preexp.pres[i])) /
                    math.log(preexp.exp) + self.epsilon)) + 1
            imax = int(
                math.ceil(
                    math.log(max / float(preexp.pres[i])) /
                    math.log(preexp.exp) - self.epsilon)) - 1
            if minpower is None or imin < minpower:
                minpower, minindex = imin, i
            if maxpower is None or imax >= maxpower:
                maxpower, maxindex = imax, i
        if minindex:
            minrational = preexp.pres[minindex - 1]
        else:
            minrational = preexp.pres[-1]
            minpower -= 1
        if maxindex != len(preexp.pres) - 1:
            maxrational = preexp.pres[maxindex + 1]
        else:
            maxrational = preexp.pres[0]
            maxpower += 1
        if extendmin:
            min = float(minrational) * float(preexp.exp)**minpower
        if extendmax:
            max = float(maxrational) * float(preexp.exp)**maxpower
        return min, max

    def getticks(self, min, max, preexp, ticklevel=None, labellevel=None):
        ticks = []
        minimin = 0
        maximax = 0
        for f in preexp.pres:
            thisticks = []
            imin = int(
                math.ceil(
                    math.log(min / float(f)) / math.log(preexp.exp) -
                    0.5 * self.epsilon))
            imax = int(
                math.floor(
                    math.log(max / float(f)) / math.log(preexp.exp) +
                    0.5 * self.epsilon))
            for i in range(imin, imax + 1):
                pos = f * tick.rational((preexp.exp, 1), power=i)
                thisticks.append(
                    tick.tick((pos.num, pos.denom),
                              ticklevel=ticklevel,
                              labellevel=labellevel))
            ticks = tick.mergeticklists(ticks, thisticks)
        return ticks
Beispiel #15
0
class autolinear(_parter):
    """partitioner to create an arbitrary number of linear paritions"""

    defaultvariants = [[tick.rational((1, 1)),
                        tick.rational((1, 2))],
                       [tick.rational((2, 1)),
                        tick.rational((1, 1))],
                       [tick.rational((5, 2)),
                        tick.rational((5, 4))],
                       [tick.rational((5, 1)),
                        tick.rational((5, 2))]]

    def __init__(self, variants=defaultvariants, extendtick=0, epsilon=1e-10):
        self.variants = variants
        self.extendtick = extendtick
        self.epsilon = epsilon

    def partfunctions(self, min, max, extendmin, extendmax):
        try:
            logmm = math.log(max - min) / math.log(10)
        except ArithmeticError:
            raise RuntimeError(
                "partitioning failed due to empty or invalid axis range")
        if logmm < 0:  # correction for rounding towards zero of the int routine
            base = tick.rational((10, 1), power=int(logmm - 1))
        else:
            base = tick.rational((10, 1), power=int(logmm))
        ticks = map(tick.rational, self.variants[0])
        useticks = [t * base for t in ticks]

        return [
            lambda d=_partdata(min=min,
                               max=max,
                               extendmin=extendmin,
                               extendmax=extendmax,
                               sign=1,
                               tickindex=-1,
                               base=tick.rational(base)): self.partfunction(d),
            lambda d=_partdata(min=min,
                               max=max,
                               extendmin=extendmin,
                               extendmax=extendmax,
                               sign=-1,
                               tickindex=0,
                               base=tick.rational(base)): self.partfunction(d)
        ]

    def partfunction(self, data):
        if data.sign == 1:
            if data.tickindex < len(self.variants) - 1:
                data.tickindex += 1
            else:
                data.tickindex = 0
                data.base.num *= 10
        else:
            if data.tickindex:
                data.tickindex -= 1
            else:
                data.tickindex = len(self.variants) - 1
                data.base.denom *= 10
        tickdists = [
            tick.rational(t) * data.base for t in self.variants[data.tickindex]
        ]
        linearparter = linear(tickdists=tickdists,
                              extendtick=self.extendtick,
                              epsilon=self.epsilon)
        return linearparter.partfunctions(min=data.min,
                                          max=data.max,
                                          extendmin=data.extendmin,
                                          extendmax=data.extendmax)[0]()
Beispiel #16
0
 def autopartfunction(self, data):
     data.exponent *= self.autoexponent
     logarithmicparter= logarithmic(tickpreexps=[preexp([tick.rational((1, 1))], data.exponent), logarithmic.pre1exp],
                                    extendtick=self.extendtick, extendlabel=self.extendlabel, epsilon=self.epsilon)
     return logarithmicparter.partfunctions(min=data.min, max=data.max, extendmin=data.extendmin, extendmax=data.extendmax)[0]()