def _computePlottedRange(self): """Convert the range requested into a plotted range.""" s = self.settings self.plottedrange = [s.min, s.max] # match the scale of this axis to another matched = False if s.match != '': # locate widget we're matching # this is ensured to be an Axis try: widget = s.get('match').getReferredWidget() except setting.InvalidType: widget = None # this looks valid + sanity checks if (widget is not None and widget != self and widget.settings.match == ''): # update if out of date if widget.docchangeset != self.document.changeset: widget._computePlottedRange() # copy the range self.plottedrange = list(widget.plottedrange) matched = True # automatic lookup of minimum if s.min == 'Auto' and not matched: self.plottedrange[0] = self.autorange[0] if s.max == 'Auto' and not matched: self.plottedrange[1] = self.autorange[1] # yuck, but sometimes it's true # tweak range to make sure things don't blow up further down the # line if ( abs(self.plottedrange[0] - self.plottedrange[1]) < ( abs(self.plottedrange[0]) + abs(self.plottedrange[1]) )*1e-8 ): self.plottedrange[1] = ( self.plottedrange[0] + max(1., self.plottedrange[0]*0.1) ) # handle axis values round the wrong way invertaxis = self.plottedrange[0] > self.plottedrange[1] if invertaxis: self.plottedrange.reverse() # make sure log axes don't blow up if s.log: if self.plottedrange[0] < 1e-99: self.plottedrange[0] = 1e-99 if self.plottedrange[1] < 1e-99: self.plottedrange[1] = 1e-99 if self.plottedrange[0] == self.plottedrange[1]: self.plottedrange[1] = self.plottedrange[0]*2 # work out tick values and expand axes if necessary if s.mode in ('numeric', 'labels'): tickclass = axisticks.AxisTicks else: tickclass = axisticks.DateTicks extendmin = extendmax = False r = s.autoRange if r == 'exact': pass elif r == 'next-tick': if s.min == 'Auto': extendmin = True if s.max == 'Auto': extendmax = True else: val = {'+2%': 0.02, '+5%': 0.05, '+10%': 0.1, '+15%': 0.15}[r] if s.log: # logarithmic logrng = abs( N.log(self.plottedrange[1]) - N.log(self.plottedrange[0]) ) if s.min == 'Auto': self.plottedrange[0] /= N.exp(logrng * val) if s.max == 'Auto': self.plottedrange[1] *= N.exp(logrng * val) else: # linear rng = self.plottedrange[1] - self.plottedrange[0] if s.min == 'Auto': self.plottedrange[0] -= rng*val if s.max == 'Auto': self.plottedrange[1] += rng*val axs = tickclass(self.plottedrange[0], self.plottedrange[1], s.MajorTicks.number, s.MinorTicks.number, extendmin = extendmin, extendmax = extendmax, logaxis = s.log ) axs.getTicks() self.plottedrange[0] = axs.minval self.plottedrange[1] = axs.maxval self.majortickscalc = axs.tickvals self.minortickscalc = axs.minorticks self.autoformat = axs.autoformat # override values if requested if len(s.MajorTicks.manualTicks) > 0: ticks = [] for i in s.MajorTicks.manualTicks: if i >= self.plottedrange[0] and i <= self.plottedrange[1]: ticks.append(i) self.majortickscalc = N.array(ticks) # invert bounds if axis was inverted if invertaxis: self.plottedrange.reverse() if self.majorticks is not None: self.majortickscalc = N.array(self.majorticks) if self.minorticks is not None: self.minortickscalc = N.array(self.minorticks) self.docchangeset = self.document.changeset
def _computePlottedRange(self): """Convert the range requested into a plotted range.""" s = self.settings self.plottedrange = [s.min, s.max] # match the scale of this axis to another matched = False if s.match != '': # locate widget we're matching # this is ensured to be an Axis try: widget = s.get('match').getReferredWidget() except setting.InvalidType: widget = None # this looks valid + sanity checks if (widget is not None and widget != self and widget.settings.match == ''): # update if out of date if widget.docchangeset != self.document.changeset: widget._computePlottedRange() # copy the range self.plottedrange = list(widget.plottedrange) matched = True # automatic lookup of minimum if s.min == 'Auto' and not matched: self.plottedrange[0] = self.autorange[0] if s.max == 'Auto' and not matched: self.plottedrange[1] = self.autorange[1] # yuck, but sometimes it's true # tweak range to make sure things don't blow up further down the # line if ( abs(self.plottedrange[0] - self.plottedrange[1]) < ( abs(self.plottedrange[0]) + abs(self.plottedrange[1]) )*1e-8 ): self.plottedrange[1] = ( self.plottedrange[0] + max(1., self.plottedrange[0]*0.1) ) # handle axis values round the wrong way invertaxis = self.plottedrange[0] > self.plottedrange[1] if invertaxis: self.plottedrange.reverse() # make sure log axes don't blow up if s.log: if self.plottedrange[0] < 1e-99: self.plottedrange[0] = 1e-99 if self.plottedrange[1] < 1e-99: self.plottedrange[1] = 1e-99 if self.plottedrange[0] == self.plottedrange[1]: self.plottedrange[1] = self.plottedrange[0]*2 r = s.autoRange if r == 'exact': pass elif r == 'next-tick': pass else: val = {'+2%': 0.02, '+5%': 0.05, '+10%': 0.1, '+15%': 0.15}[r] if s.log: # logarithmic logrng = abs( N.log(self.plottedrange[1]) - N.log(self.plottedrange[0]) ) if s.min == 'Auto': self.plottedrange[0] /= N.exp(logrng * val) if s.max == 'Auto': self.plottedrange[1] *= N.exp(logrng * val) else: # linear rng = self.plottedrange[1] - self.plottedrange[0] if s.min == 'Auto': self.plottedrange[0] -= rng*val if s.max == 'Auto': self.plottedrange[1] += rng*val self.computeTicks() # invert bounds if axis was inverted if invertaxis: self.plottedrange.reverse() self.docchangeset = self.document.changeset