예제 #1
0
 def view_limits(self, dmin, dmax):
     if self._symmetric:
         maxabs = max(abs(dmin), abs(dmax))
         dmin = -maxabs
         dmax = maxabs
     dmin, dmax = mtransforms.nonsingular(dmin, dmax, expander = 0.05)
     return np.take(self.bin_boundaries(dmin, dmax), [0,-1])
예제 #2
0
    def autoscale(self):
        'Try to choose the view limits intelligently'
        b = self._transform.base
        vmin, vmax = self.axis.get_data_interval()
        if vmax < vmin:
            vmin, vmax = vmax, vmin

        if not is_decade(abs(vmin), b):
            if vmin < 0:
                vmin = -decade_up(-vmin, b)
            else:
                vmin = decade_down(vmin, b)
        if not is_decade(abs(vmax), b):
            if vmax < 0:
                vmax = -decade_down(-vmax, b)
            else:
                vmax = decade_up(vmax, b)

        if vmin == vmax:
            if vmin < 0:
                vmin = -decade_up(-vmin, b)
                vmax = -decade_down(-vmax, b)
            else:
                vmin = decade_down(vmin, b)
                vmax = decade_up(vmax, b)
        result = mtransforms.nonsingular(vmin, vmax)
        return result
예제 #3
0
파일: ticks.py 프로젝트: tianluyuan/dashi
    def view_limits(self, vmin, vmax):
        """
        Try to choose the view limits intelligently. In contrast to the stock
        LogLocator, this version always pads by one decade so that the contents
        of the largest and smallest histogram bins can be seen even if they
        fall on a decade.
        """
        b = self._base

        if vmax < vmin:
            vmin, vmax = vmax, vmin

        if self.axis.axes.name == 'polar':
            vmax = math.ceil(math.log(vmax) / math.log(b))
            vmin = b**(vmax - self.numdecs)
            return vmin, vmax

        minpos = self.axis.get_minpos()

        if minpos <= 0 or not np.isfinite(minpos):
            raise ValueError(
                "Data has no positive values, and therefore can not be "
                "log-scaled.")

        if vmin <= minpos:
            vmin = minpos

        vmin = mticker.decade_down(vmin * (1 - 1e-10), self._base)
        vmax = mticker.decade_up(vmax * (1 + 1e-10), self._base)

        if vmin == vmax:
            vmin = mticker.decade_down(vmin, self._base)
            vmax = mticker.decade_up(vmax, self._base)
        result = mtransforms.nonsingular(vmin, vmax)
        return result
예제 #4
0
    def autoscale(self):
        "Try to choose the view limits intelligently"
        b = self._transform.base
        vmin, vmax = self.axis.get_data_interval()
        if vmax < vmin:
            vmin, vmax = vmax, vmin

        if not is_decade(abs(vmin), b):
            if vmin < 0:
                vmin = -decade_up(-vmin, b)
            else:
                vmin = decade_down(vmin, b)
        if not is_decade(abs(vmax), b):
            if vmax < 0:
                vmax = -decade_down(-vmax, b)
            else:
                vmax = decade_up(vmax, b)

        if vmin == vmax:
            if vmin < 0:
                vmin = -decade_up(-vmin, b)
                vmax = -decade_down(-vmax, b)
            else:
                vmin = decade_down(vmin, b)
                vmax = decade_up(vmax, b)
        result = mtransforms.nonsingular(vmin, vmax)
        return result
예제 #5
0
    def view_limits(self, vmin, vmax):
        'Try to choose the view limits intelligently'
        b = self._transform.base
        if vmax<vmin:
            vmin, vmax = vmax, vmin

        if not is_decade(abs(vmin), b):
            if vmin < 0:
                vmin = -decade_up(-vmin, b)
            else:
                vmin = decade_down(vmin, b)
        if not is_decade(abs(vmax), b):
            if vmax < 0:
                vmax = -decade_down(-vmax, b)
            else:
                vmax = decade_up(vmax, b)

        if vmin == vmax:
            if vmin < 0:
                vmin = -decade_up(-vmin, b)
                vmax = -decade_down(-vmax, b)
            else:
                vmin = decade_down(vmin, b)
                vmax = decade_up(vmax, b)
        result = mtransforms.nonsingular(vmin, vmax)
        return result
예제 #6
0
 def zoom(self, direction):
     "Zoom in/out on axis; if direction is >0 zoom in, else zoom out"
     vmin, vmax = self.axis.get_view_interval()
     vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander = 0.05)
     interval = abs(vmax-vmin)
     step = 0.1*interval*direction
     self.axis.set_view_interval(vmin + step, vmax - step, ignore=True)
예제 #7
0
 def view_limits(self, dmin, dmax):
     if self._symmetric:
         maxabs = max(abs(dmin), abs(dmax))
         dmin = -maxabs
         dmax = maxabs
     dmin, dmax = mtransforms.nonsingular(dmin, dmax, expander=0.05)
     return np.take(self.bin_boundaries(dmin, dmax), [0, -1])
예제 #8
0
    def view_limits(self, vmin, vmax):
        'Try to choose the view limits intelligently'
        b = self._transform.base
        if vmax < vmin:
            vmin, vmax = vmax, vmin

        if not is_decade(abs(vmin), b):
            if vmin < 0:
                vmin = -decade_up(-vmin, b)
            else:
                vmin = decade_down(vmin, b)
        if not is_decade(abs(vmax), b):
            if vmax < 0:
                vmax = -decade_down(-vmax, b)
            else:
                vmax = decade_up(vmax, b)

        if vmin == vmax:
            if vmin < 0:
                vmin = -decade_up(-vmin, b)
                vmax = -decade_down(-vmax, b)
            else:
                vmin = decade_down(vmin, b)
                vmax = decade_up(vmax, b)
        result = mtransforms.nonsingular(vmin, vmax)
        return result
예제 #9
0
def test_nonsingular():
    # test for zero-expansion type cases; other cases may be added later
    zero_expansion = np.array([-0.001, 0.001])
    cases = [(0, np.nan), (0, 0), (0, 7.9e-317)]
    for args in cases:
        out = np.array(mtransforms.nonsingular(*args))
        assert_array_equal(out, zero_expansion)
예제 #10
0
    def autoscale(self):
        'Try to choose the view limits intelligently'
        vmin, vmax = self.axis.get_data_interval()
        if vmax < vmin:
            vmin, vmax = vmax, vmin

        minpos = self.axis.get_minpos()

        if minpos <= 0:
            raise ValueError(
                "Data has no positive values, and therefore can not be log-scaled."
            )

        if vmin <= minpos:
            vmin = minpos

        if not is_decade(vmin, self._base):
            vmin = decade_down(vmin, self._base)
        if not is_decade(vmax, self._base): vmax = decade_up(vmax, self._base)

        if vmin == vmax:
            vmin = decade_down(vmin, self._base)
            vmax = decade_up(vmax, self._base)
        result = mtransforms.nonsingular(vmin, vmax)
        return result
예제 #11
0
    def __call__(self, x, pos=None):
        "Return the format for tick val x at position pos"

        vmin, vmax = self.axis.get_view_interval()
        vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander=0.05)
        d = abs(vmax - vmin)
        b = self._base
        if x == 0:
            return "0"
        sign = np.sign(x)
        # only label the decades
        fx = math.log(abs(x)) / math.log(b)
        isDecade = self.is_decade(fx)
        if not isDecade and self.labelOnlyBase:
            s = ""
        # if 0: pass
        elif fx > 10000:
            s = "%1.0e" % fx
        # elif x<1: s = '$10^{%d}$'%fx
        # elif x<1: s =  '10^%d'%fx
        elif fx < 1:
            s = "%1.0e" % fx
        else:
            s = self.pprint_val(fx, d)
        if sign == -1:
            s = "-%s" % s

        return self.fix_minus(s)
예제 #12
0
    def view_limits(self, vmin, vmax):
        'Try to choose the view limits intelligently'
        b = self._base

        if vmax<vmin:
            vmin, vmax = vmax, vmin

        if self.axis.axes.name == 'polar':
            vmax = math.ceil(math.log(vmax) / math.log(b))
            vmin = b ** (vmax - self.numdecs)
            return vmin, vmax

        minpos = self.axis.get_minpos()

        if minpos<=0 or not np.isfinite(minpos):
            raise ValueError(
                "Data has no positive values, and therefore can not be log-scaled.")

        if vmin <= minpos:
            vmin = minpos

        if not is_decade(vmin,self._base): vmin = decade_down(vmin,self._base)
        if not is_decade(vmax,self._base): vmax = decade_up(vmax,self._base)

        if vmin==vmax:
            vmin = decade_down(vmin,self._base)
            vmax = decade_up(vmax,self._base)
        result = mtransforms.nonsingular(vmin, vmax)
        return result
예제 #13
0
    def __call__(self, x, pos=None):
        'Return the format for tick val x at position pos'


        vmin, vmax = self.axis.get_view_interval()
        vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander = 0.05)
        d = abs(vmax-vmin)
        b=self._base
        if x == 0:
            return '0'
        sign = np.sign(x)
        # only label the decades
        fx = math.log(abs(x))/math.log(b)
        isDecade = self.is_decade(fx)
        if not isDecade and self.labelOnlyBase: s = ''
        #if 0: pass
        elif fx>10000: s= '%1.0e'%fx
        #elif x<1: s = '$10^{%d}$'%fx
        #elif x<1: s =  '10^%d'%fx
        elif fx<1: s =  '%1.0e'%fx
        else        : s =  self.pprint_val(fx,d)
        if sign == -1:
            s =  '-%s' % s

        return self.fix_minus(s)
예제 #14
0
def test_nonsingular():
    # test for zero-expansion type cases; other cases may be added later
    zero_expansion = np.array([-0.001, 0.001])
    cases = [(0, np.nan), (0, 0), (0, 7.9e-317)]
    for args in cases:
        out = np.array(mtrans.nonsingular(*args))
        assert_array_equal(out, zero_expansion)
예제 #15
0
    def view_limits(self, vmin, vmax):
        'Try to choose the view limits intelligently'
        b = self._base

        if vmax < vmin:
            vmin, vmax = vmax, vmin

        if self.axis.axes.name == 'polar':
            vmax = math.ceil(math.log(vmax) / math.log(b))
            vmin = b**(vmax - self.numdecs)
            return vmin, vmax

        minpos = self.axis.get_minpos()

        if minpos <= 0 or not np.isfinite(minpos):
            raise ValueError(
                "Data has no positive values, and therefore can not be log-scaled."
            )

        if vmin <= minpos:
            vmin = minpos

        if not is_decade(vmin, self._base):
            vmin = decade_down(vmin, self._base)
        if not is_decade(vmax, self._base): vmax = decade_up(vmax, self._base)

        if vmin == vmax:
            vmin = decade_down(vmin, self._base)
            vmax = decade_up(vmax, self._base)
        result = mtransforms.nonsingular(vmin, vmax)
        return result
예제 #16
0
    def __call__(self, x, pos=None):
        'Return the format for tick val *x* at position *pos*'


        vmin, vmax = self.axis.get_view_interval()
        vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander = 0.05)
        d = abs(vmax-vmin)
        b=self._base
        if x == 0:
            return '0'
        sign = np.sign(x)
        # only label the decades
        fx = math.log(abs(x))/math.log(b)
        isDecade = is_close_to_int(fx)
        if not isDecade and self.labelOnlyBase: s = ''
        #if 0: pass
        elif fx>10000: s= '%1.0e'%fx
        #elif x<1: s = '$10^{%d}$'%fx
        #elif x<1: s =  '10^%d'%fx
        elif fx<1: s =  '%1.0e'%fx
        else        : s =  self.pprint_val(fx,d)
        if sign == -1:
            s =  '-%s' % s

        return self.fix_minus(s)
예제 #17
0
    def view_limits(self, vmin, vmax):
        """
        select a scale for the range from vmin to vmax

        Normally This will be overridden.
        """
        return mtransforms.nonsingular(vmin, vmax)
예제 #18
0
    def view_limits(self, vmin, vmax):
        """
        select a scale for the range from vmin to vmax

        Normally This will be overridden.
        """
        return mtransforms.nonsingular(vmin, vmax)
예제 #19
0
파일: ticks.py 프로젝트: IceCube-SPNO/dashi
    def view_limits(self, vmin, vmax):
        """
        Try to choose the view limits intelligently. In contrast to the stock
        LogLocator, this version always pads by one decade so that the contents
        of the largest and smallest histogram bins can be seen even if they
        fall on a decade.
        """
        b = self._base

        if vmax < vmin:
            vmin, vmax = vmax, vmin

        if self.axis.axes.name == 'polar':
            vmax = math.ceil(math.log(vmax) / math.log(b))
            vmin = b ** (vmax - self.numdecs)
            return vmin, vmax

        minpos = self.axis.get_minpos()

        if minpos <= 0 or not np.isfinite(minpos):
            raise ValueError(
                "Data has no positive values, and therefore can not be "
                "log-scaled.")

        if vmin <= minpos:
            vmin = minpos
        
        vmin = mticker.decade_down(vmin*(1-1e-10), self._base)
        vmax = mticker.decade_up(vmax*(1+1e-10), self._base)

        if vmin == vmax:
            vmin = mticker.decade_down(vmin, self._base)
            vmax = mticker.decade_up(vmax, self._base)
        result = mtransforms.nonsingular(vmin, vmax)
        return result
예제 #20
0
    def __init__(self, x, y, ids, nx, malicious_ids):

        self.malicious_ids = malicious_ids

        self.x = np.array(x, float)
        self.y = np.array(y, float)
        self.ids = ids

        self.xmin = np.amin(x)
        self.xmax = np.amax(x)
        self.ymin = np.amin(y)
        self.ymax = np.amax(y)

        # to avoid issues with singular data, expand the min/max pairs
        self.xmin, self.xmax = mtrans.nonsingular(
                self.xmin,
                self.xmax,
                expander=0.1)
        self.ymin, self.ymax = mtrans.nonsingular(
                self.ymin,
                self.ymax,
                expander=0.1)

        # In the x-direction, the hexagons exactly cover the region from
        # xmin to xmax. Need some padding to avoid roundoff errors.
        padding = 1.e-9 * (self.xmax - self.xmin)
        self.xmin -= padding
        self.xmax += padding

        ## Deal with very small values
        if self.xmax - self.xmin < epsilon:
            self.xmin -= epsilon / 2
            self.xmax += epsilon / 2
        if self.ymax - self.ymin < epsilon:
            self.ymin -= epsilon / 2
            self.ymax += epsilon / 2

        self.nx = nx
        self.size = (self.xmax - self.xmin) / self.nx
        self.nx = int(math.ceil((self.xmax - self.xmin) /
            (math.sqrt(3) * self.size))) + 1
        self.ny = int(math.ceil((self.ymax - self.ymin) /
            self.size)) + 1

        self.x_scale = (self.x - self.xmin) / (self.size * math.sqrt(3))
        self.y_scale = (self.y - self.ymin) / self.size
예제 #21
0
    def zoom(self, direction):
        "Zoom in/out on axis; if direction is >0 zoom in, else zoom out"

        vmin, vmax = self.axis.get_view_interval()
        vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander = 0.05)
        interval = abs(vmax-vmin)
        step = 0.1*interval*direction
        self.axis.set_view_interval(vmin + step, vmax - step, ignore=True)
예제 #22
0
 def autoscale(self):
     dmin, dmax = self.axis.get_data_interval()
     if self._symmetric:
         maxabs = max(abs(dmin), abs(dmax))
         dmin = -maxabs
         dmax = maxabs
     dmin, dmax = mtransforms.nonsingular(dmin, dmax, expander=0.05)
     return np.take(self.bin_boundaries(dmin, dmax), [0, -1])
예제 #23
0
 def autoscale(self):
     dmin, dmax = self.axis.get_data_interval()
     if self._symmetric:
         maxabs = max(abs(dmin), abs(dmax))
         dmin = -maxabs
         dmax = maxabs
     dmin, dmax = mtransforms.nonsingular(dmin, dmax, expander=0.05)
     return np.take(self.bin_boundaries(dmin, dmax), [0, -1])
예제 #24
0
    def tick_values(self, vmin, vmax):
        vmin, vmax = mtransforms.nonsingular(vmin,
                                             vmax,
                                             expander=1e-7,
                                             tiny=1e-13)

        self.ndays = float(abs(vmax - vmin))

        utime = netcdftime.utime(self.date_unit, self.calendar)
        lower = utime.num2date(vmin)
        upper = utime.num2date(vmax)

        resolution, n = self.compute_resolution(vmin, vmax, lower, upper)

        if resolution == 'YEARLY':
            # TODO START AT THE BEGINNING OF A DECADE/CENTURY/MILLENIUM as
            # appropriate.
            years = self._max_n_locator.tick_values(lower.year, upper.year)
            ticks = [netcdftime.datetime(int(year), 1, 1) for year in years]
        elif resolution == 'MONTHLY':
            # TODO START AT THE BEGINNING OF A DECADE/CENTURY/MILLENIUM as
            # appropriate.
            months_offset = self._max_n_locator.tick_values(0, n)
            ticks = []
            for offset in months_offset:
                year = lower.year + np.floor((lower.month + offset) / 12)
                month = ((lower.month + offset) % 12) + 1
                ticks.append(netcdftime.datetime(int(year), int(month), 1))
        elif resolution == 'DAILY':
            # TODO: It would be great if this favoured multiples of 7.
            days = self._max_n_locator_days.tick_values(vmin, vmax)
            ticks = [utime.num2date(dt) for dt in days]
        elif resolution == 'HOURLY':
            hour_unit = 'hours since 2000-01-01'
            hour_utime = netcdftime.utime(hour_unit, self.calendar)
            in_hours = hour_utime.date2num([lower, upper])
            hours = self._max_n_locator.tick_values(in_hours[0], in_hours[1])
            ticks = [hour_utime.num2date(dt) for dt in hours]
        elif resolution == 'MINUTELY':
            minute_unit = 'minutes since 2000-01-01'
            minute_utime = netcdftime.utime(minute_unit, self.calendar)
            in_minutes = minute_utime.date2num([lower, upper])
            minutes = self._max_n_locator.tick_values(in_minutes[0],
                                                      in_minutes[1])
            ticks = [minute_utime.num2date(dt) for dt in minutes]
        elif resolution == 'SECONDLY':
            second_unit = 'seconds since 2000-01-01'
            second_utime = netcdftime.utime(second_unit, self.calendar)
            in_seconds = second_utime.date2num([lower, upper])
            seconds = self._max_n_locator.tick_values(in_seconds[0],
                                                      in_seconds[1])
            ticks = [second_utime.num2date(dt) for dt in seconds]
        else:
            msg = 'Resolution {} not implemented yet.'.format(resolution)
            raise ValueError(msg)

        return utime.date2num(ticks)
예제 #25
0
파일: ticks.py 프로젝트: mcoughlin/gwpy
 def get_view_interval(self):
     vmin, vmax = self.axis.get_view_interval()
     if self.epoch:
         vmin -= float(self.epoch.gps)
         vmax -= float(self.epoch.gps)
     if self._scale:
         vmin /= self._scale
         vmax /= self._scale
     return mtransforms.nonsingular(vmin, vmax, expander = 0.05)
예제 #26
0
    def __call__(self):
        vmin, vmax = self.axis.get_view_interval()
        vmin, vmax = nonsingular(vmin, vmax, expander = 0.05)
        vmin = vmin ** self.exponent
        vmax = vmax ** self.exponent
        if vmax<vmin:
            vmin, vmax = vmax, vmin

        ticklocs = np.linspace(vmin, vmax, num=self.numticks, endpoint=True)
        return self.raise_if_exceeds(ticklocs ** (1.0 / self.exponent))
예제 #27
0
    def __call__(self):
        vmin, vmax = self.axis.get_view_interval()
        vmin, vmax = nonsingular(vmin, vmax, expander=0.05)
        vmin = vmin**self.exponent
        vmax = vmax**self.exponent
        if vmax < vmin:
            vmin, vmax = vmax, vmin

        ticklocs = np.linspace(vmin, vmax, num=self.numticks, endpoint=True)
        return self.raise_if_exceeds(ticklocs**(1.0 / self.exponent))
예제 #28
0
    def tick_values(self, vmin, vmax):
        vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander=1e-7,
                                             tiny=1e-13)

        self.ndays = float(abs(vmax - vmin))

        utime = cftime.utime(self.date_unit, self.calendar)
        lower = utime.num2date(vmin)
        upper = utime.num2date(vmax)

        resolution, n = self.compute_resolution(vmin, vmax, lower, upper)

        if resolution == 'YEARLY':
            # TODO START AT THE BEGINNING OF A DECADE/CENTURY/MILLENIUM as
            # appropriate.
            years = self._max_n_locator.tick_values(lower.year, upper.year)
            ticks = [cftime.datetime(int(year), 1, 1) for year in years]
        elif resolution == 'MONTHLY':
            # TODO START AT THE BEGINNING OF A DECADE/CENTURY/MILLENIUM as
            # appropriate.
            months_offset = self._max_n_locator.tick_values(0, n)
            ticks = []
            for offset in months_offset:
                year = lower.year + np.floor((lower.month + offset) / 12)
                month = ((lower.month + offset) % 12) + 1
                ticks.append(cftime.datetime(int(year), int(month), 1))
        elif resolution == 'DAILY':
            # TODO: It would be great if this favoured multiples of 7.
            days = self._max_n_locator_days.tick_values(vmin, vmax)
            ticks = [utime.num2date(dt) for dt in days]
        elif resolution == 'HOURLY':
            hour_unit = 'hours since 2000-01-01'
            hour_utime = cftime.utime(hour_unit, self.calendar)
            in_hours = hour_utime.date2num([lower, upper])
            hours = self._max_n_locator.tick_values(in_hours[0], in_hours[1])
            ticks = [hour_utime.num2date(dt) for dt in hours]
        elif resolution == 'MINUTELY':
            minute_unit = 'minutes since 2000-01-01'
            minute_utime = cftime.utime(minute_unit, self.calendar)
            in_minutes = minute_utime.date2num([lower, upper])
            minutes = self._max_n_locator.tick_values(in_minutes[0],
                                                      in_minutes[1])
            ticks = [minute_utime.num2date(dt) for dt in minutes]
        elif resolution == 'SECONDLY':
            second_unit = 'seconds since 2000-01-01'
            second_utime = cftime.utime(second_unit, self.calendar)
            in_seconds = second_utime.date2num([lower, upper])
            seconds = self._max_n_locator.tick_values(in_seconds[0],
                                                      in_seconds[1])
            ticks = [second_utime.num2date(dt) for dt in seconds]
        else:
            msg = 'Resolution {} not implemented yet.'.format(resolution)
            raise ValueError(msg)

        return utime.date2num(ticks)
예제 #29
0
 def view_limits(self, dmin, dmax):
     """
     Set the view limits to the nearest multiples of base that
     contain the data
     """
     vmin = self._base.le(dmin)
     vmax = self._base.ge(dmax)
     if vmin==vmax:
         vmin -=1
         vmax +=1
     return mtransforms.nonsingular(vmin, vmax)
예제 #30
0
 def __call__(self):
     vmin, vmax = self.axis.get_view_interval()
     vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander=0.05)
     locs = self.bin_boundaries(vmin, vmax)
     prune = self._prune
     if prune == "lower":
         locs = locs[1:]
     elif prune == "upper":
         locs = locs[:-1]
     elif prune == "both":
         locs = locs[1:-1]
     return locs
예제 #31
0
    def view_limits(self, dmin, dmax):
        """
        Set the view limits to the nearest multiples of base that
        contain the data
        """
        vmin = self._base.le(dmin)
        vmax = self._base.ge(dmax)
        if vmin == vmax:
            vmin -= 1
            vmax += 1

        return mtransforms.nonsingular(vmin, vmax)
예제 #32
0
    def view_limits(self, dmin, dmax):
        """
        Set the view limits to the nearest multiples of base that
        contain the data
        """
        vmin = self._base.le(math.copysign(math.sqrt(abs(dmin)), dmin))
        vmax = self._base.ge(math.sqrt(dmax))
        if vmin == vmax:
            vmin -= 1
            vmax += 1

        return mtransforms.nonsingular(math.copysign(vmin**2, vmin), vmax**2)
예제 #33
0
 def __call__(self):
     vmin, vmax = self.axis.get_view_interval()
     vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander = 0.05)
     locs = self.bin_boundaries(vmin, vmax)
     prune = self._prune
     if prune=='lower':
         locs = locs[1:]
     elif prune=='upper':
         locs = locs[:-1]
     elif prune=='both':
         locs = locs[1:-1]
     return self.raise_if_exceeds(locs)
예제 #34
0
 def __call__(self):
     'Return the locations of the ticks'
     vmin, vmax = self.axis.get_view_interval()
     vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander = 0.05)
     if vmax<vmin:
         vmin, vmax = vmax, vmin
     if (vmin, vmax) in self.presets:
         return self.presets[(vmin, vmax)]
     if self.numticks is None:
         self._set_numticks()
     if self.numticks==0: return []
     ticklocs = np.linspace(vmin, vmax, self.numticks)
     return self.raise_if_exceeds(ticklocs)
예제 #35
0
    def autoscale(self):
        """
    Sets the view limits to the nearest multiples of base that contain the data.
        """
        # requires matplotlib >= 0.98.0
        (vmin, vmax) = self.axis.get_data_interval()

        locs = self._get_default_locs(vmin, vmax)
        (vmin, vmax) = locs[[0, -1]]
        if vmin == vmax:
            vmin -= 1
            vmax += 1
        return nonsingular(vmin, vmax)
예제 #36
0
    def autoscale(self):
        """
    Sets the view limits to the nearest multiples of base that contain the data.
        """
        # requires matplotlib >= 0.98.0
        (vmin, vmax) = self.axis.get_data_interval()

        locs = self._get_default_locs(vmin, vmax)
        (vmin, vmax) = locs[[0, -1]]
        if vmin == vmax:
            vmin -= 1
            vmax += 1
        return nonsingular(vmin, vmax)
예제 #37
0
    def __call__(self, x, pos=None):
        """
        Return the format for tick val *x*.
        """
        if x == 0.0:  # Symlog
            return '0'

        x = abs(x)

        vmin, vmax = self.axis.get_view_interval()
        vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander=0.05)
        s = self._num_to_string(x, vmin, vmax)
        return self.fix_minus(s)
예제 #38
0
 def __call__(self):
     vmin, vmax = self.axis.get_view_interval()
     vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander=0.05)
     locs = self.bin_boundaries(vmin, vmax)
     #print 'locs=', locs
     prune = self._prune
     if prune == 'lower':
         locs = locs[1:]
     elif prune == 'upper':
         locs = locs[:-1]
     elif prune == 'both':
         locs = locs[1:-1]
     return self.raise_if_exceeds(locs)
예제 #39
0
 def view_limits(self, vmin, vmax):
     'Try to choose the view limits intelligently'
     if vmax<vmin:
         vmin, vmax = vmax, vmin
     if vmin==vmax:
         vmin-=1
         vmax+=1
     exponent, remainder = divmod(math.log10(vmax - vmin), 1)
     if remainder < 0.5:
         exponent -= 1
     scale = 10**(-exponent)
     vmin = math.floor(scale*vmin)/scale
     vmax = math.ceil(scale*vmax)/scale
     return mtransforms.nonsingular(vmin, vmax)
예제 #40
0
파일: ticks.py 프로젝트: mcoughlin/gwpy
 def tick_values(self, vmin, vmax):
     """Return the ticks for this axis
     """
     vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander=1e-13,
                                                      tiny=1e-14)
     locs = self.bin_boundaries(vmin, vmax)
     prune = self._prune
     if prune == 'lower':
         locs = locs[1:]
     elif prune == 'upper':
         locs = locs[:-1]
     elif prune == 'both':
         locs = locs[1:-1]
     return self.raise_if_exceeds(locs)
예제 #41
0
 def pan(self, numsteps):
     'Pan numticks (can be positive or negative)'
     ticks = self()
     numticks = len(ticks)
     vmin, vmax = self.axis.get_view_interval()
     vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander = 0.05)
     if numticks>2:
         step = numsteps*abs(ticks[0]-ticks[1])
     else:
         d = abs(vmax-vmin)
         step = numsteps*d/6.
     vmin += step
     vmax += step
     self.axis.set_view_interval(vmin, vmax, ignore=True)
예제 #42
0
    def autoscale(self):
        """
        Set the view limits to the nearest multiples of base that
        contain the data
        """
        dmin, dmax = self.axis.get_data_interval()

        vmin = self._base.le(dmin)
        vmax = self._base.ge(dmax)
        if vmin == vmax:
            vmin -= 1
            vmax += 1

        return mtransforms.nonsingular(vmin, vmax)
예제 #43
0
    def autoscale(self):
        """
        Set the view limits to the nearest multiples of base that
        contain the data
        """
        dmin, dmax = self.axis.get_data_interval()

        vmin = self._base.le(dmin)
        vmax = self._base.ge(dmax)
        if vmin == vmax:
            vmin -= 1
            vmax += 1

        return mtransforms.nonsingular(vmin, vmax)
예제 #44
0
 def autoscale(self):
   self.verify_intervals()
   dmin, dmax = self.axis.get_data_interval()
   if dmin > dmax:
     dmin, dmax = dmax, dmin
   if dmin == dmax:
     dmin -= 1
     dmax += 1
   exp, rem = divmod(math.log(dmax - dmin, 2), 1)
   if rem > 0.5:
     exp -= 1
   scale = 2**(-exp)
   dmin = math.floor(scale*dmin)/scale
   dmax = math.ceil(scale*dmax)/scale
   return nonsingular(dmin, dmax)
예제 #45
0
    def plot(self, experiment, **kwargs):
        """Plot a faceted histogram view of a channel"""
        
        #kwargs.setdefault('histtype', 'stepfilled')
        #kwargs.setdefault('alpha', 0.5)
        kwargs.setdefault('edgecolor', 'none')
        #kwargs.setdefault('mincnt', 1)
        #kwargs.setdefault('bins', 'log')
        kwargs.setdefault('antialiased', True)
        
        if not self.subset:
            x = experiment.data
        else:
            x = experiment.query(self.subset)
            
        xmin, xmax = (np.amin(x[self.xchannel]), np.amax(x[self.xchannel]))
        ymin, ymax = (np.amin(x[self.ychannel]), np.amax(x[self.ychannel]))
        # to avoid issues with singular data, expand the min/max pairs
        xmin, xmax = mtrans.nonsingular(xmin, xmax, expander=0.1)
        ymin, ymax = mtrans.nonsingular(ymin, ymax, expander=0.1)
        
        extent = (xmin, xmax, ymin, ymax)
        kwargs.setdefault('extent', extent)
        
        xbins = num_hist_bins(experiment[self.xchannel])
        ybins = num_hist_bins(experiment[self.ychannel])
        bins = np.mean([xbins, ybins])
        
        kwargs.setdefault('bins', bins) # Do not move above.  don't ask.

        g = sns.FacetGrid(x, 
                          col = (self.xfacet if self.xfacet else None),
                          row = (self.yfacet if self.yfacet else None),
                          hue = (self.huefacet if self.huefacet else None))
        
        g.map(plt.hexbin, self.xchannel, self.ychannel, **kwargs)
예제 #46
0
    def autoscale(self):
        """
        Set the view limits to the nearest multiples of base that
        contain the data
        """

        self.verify_intervals()
        dmin, dmax = self.dataInterval.get_bounds()

        vmin = self._base.le(dmin)
        vmax = self._base.ge(dmax)
        if vmin == vmax:
            vmin -= 1
            vmax += 1

        return mtrans.nonsingular(vmin, vmax)
예제 #47
0
    def pan(self, numsteps):
        'Pan numticks (can be positive or negative)'
        ticks = self()
        numticks = len(ticks)

        vmin, vmax = self.axis.get_view_interval()
        vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander = 0.05)
        if numticks>2:
            step = numsteps*abs(ticks[0]-ticks[1])
        else:
            d = abs(vmax-vmin)
            step = numsteps*d/6.

        vmin += step
        vmax += step
        self.axis.set_view_interval(vmin, vmax, ignore=True)
예제 #48
0
    def autoscale(self):
        """
        Set the view limits to the nearest multiples of base that
        contain the data
        """

        self.verify_intervals()
        dmin, dmax = self.dataInterval.get_bounds()

        vmin = self._base.le(dmin)
        vmax = self._base.ge(dmax)
        if vmin==vmax:
            vmin -=1
            vmax +=1

        return mtrans.nonsingular(vmin, vmax)
예제 #49
0
 def view_limits(self, vmin, vmax):
     'Try to choose the view limits intelligently'
     if vmax<vmin:
         vmin, vmax = vmax, vmin
     minpos = self.axis.get_minpos()
     if minpos<=0:
         raise ValueError(
             "Data has no positive values, and therefore can not be log-scaled.")
     if vmin <= minpos:
         vmin = minpos
     if not is_decade(vmin,self._base): vmin = decade_down(vmin,self._base)
     if not is_decade(vmax,self._base): vmax = decade_up(vmax,self._base)
     if vmin==vmax:
         vmin = decade_down(vmin,self._base)
         vmax = decade_up(vmax,self._base)
     result = mtransforms.nonsingular(vmin, vmax)
     return result
예제 #50
0
    def view_limits(self, dmin, dmax):
        """
        Set the view limits to the nearest multiples of base that
        contain the data
        """
        base = self._select_base(dmin, dmax)
        if mpl.rcParams['axes.autolimit_mode'] == 'round_numbers':
            vmin = base.le(dmin)
            vmax = base.ge(dmax)
            if vmin == vmax:
                vmin -= 1
                vmax += 1
        else:
            vmin = dmin
            vmax = dmax

        return mtransforms.nonsingular(vmin, vmax)
    def view_limits(self, vmin, vmax):
        'Try to choose the view limits intelligently'
        b = self._base
        
        if vmax < vmin:
            vmin, vmax = vmax, vmin

        if self.axis.axes.name == 'polar':
            vmax = math.ceil(math.log(vmax - self.zero) / math.log(b))
            vmin = b ** (vmax - self.numdecs)
            return vmin, vmax

        minpos = self.axis.get_minpos()

        if (self.sign > 0.0) :
            if vmax <= self.zero or not np.isfinite(minpos):
                raise ValueError(
                    "Data has no positive values, and therefore can not be "
                    "log-scaled.")
        else:
            if vmin >= self.zero or not np.isfinite(minpos):
                raise ValueError(
                    "Data has no positive values, and therefore can not be "
                    "log-scaled.")
            
        if not is_decade((vmin - self.zero) * self.sign, self._base):
            if self.sign > 0.0:
                vmin = decade_down((vmin - self.zero) * self.sign, self._base) + self.zero
            else:
                vmin = decade_up((vmin - self.zero) * self.sign, self._base) * self.sign + self.zero
        if not is_decade((vmax - self.zero) * self.sign, self._base):
            if self.sign > 0.0:
                vmax = decade_up((vmax - self.zero) * self.sign, self._base) + self.zero
            else:
                vmax = decade_down((vmax - self.zero) * self.sign, self._base) * self.sign + self.zero
        if vmin == vmax:
            if (self.sign > 0.0):
                vmin = decade_down((vmin - self.zero) * self.sign, self._base) + self.zero
                vmax = decade_up((vmax - self.zero) * self.sign, self._base) + self.zero
            else:
                vmin = decade_up((vmin - self.zero) * self.sign, self._base) * self.sign + self.zero
                vmax = decade_down((vmax - self.zero) * self.sign, self._base) * self.sign + self.zero
            
        result = mtransforms.nonsingular(vmin, vmax)
        return result
예제 #52
0
    def __call__(self):
        'Return the locations of the ticks'

        vmin, vmax = self.axis.get_view_interval()
        vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander=0.05)
        if vmax < vmin:
            vmin, vmax = vmax, vmin

        if (vmin, vmax) in self.presets:
            return self.presets[(vmin, vmax)]

        if self.numticks is None:
            self._set_numticks()

        if self.numticks == 0: return []
        ticklocs = np.linspace(vmin, vmax, self.numticks)

        return ticklocs
예제 #53
0
    def __call__(self):
        "Return the locations of the ticks"

        vmin, vmax = self.axis.get_view_interval()
        vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander=0.05)
        if vmax < vmin:
            vmin, vmax = vmax, vmin

        if self.presets.has_key((vmin, vmax)):
            return self.presets[(vmin, vmax)]

        if self.numticks is None:
            self._set_numticks()

        if self.numticks == 0:
            return []
        ticklocs = np.linspace(vmin, vmax, self.numticks)

        return ticklocs
예제 #54
0
    def view_limits(self, vmin, vmax):
        'Try to choose the view limits intelligently'

        if vmax < vmin:
            vmin, vmax = vmax, vmin

        if vmin == vmax:
            vmin -= 1
            vmax += 1

        exponent, remainder = divmod(math.log10(vmax - vmin), 1)

        if remainder < 0.5:
            exponent -= 1
        scale = 10**(-exponent)
        vmin = math.floor(scale * vmin) / scale
        vmax = math.ceil(scale * vmax) / scale

        return mtransforms.nonsingular(vmin, vmax)
예제 #55
0
    def autoscale(self):
        'Try to choose the view limits intelligently'
        self.verify_intervals()

        vmin, vmax = self.dataInterval.get_bounds()
        if vmax<vmin:
            vmin, vmax = vmax, vmin

        minpos = self.dataInterval.minpos()

        if minpos<=0:
            raise RuntimeError('No positive data to plot')
        if vmin<=0:
            vmin = minpos
        if not is_decade(vmin,self._base): vmin = decade_down(vmin,self._base)
        if not is_decade(vmax,self._base): vmax = decade_up(vmax,self._base)
        if vmin==vmax:
            vmin = decade_down(vmin,self._base)
            vmax = decade_up(vmax,self._base)
        return mtrans.nonsingular(vmin, vmax)
예제 #56
0
    def view_limits(self, data_min, data_max):
        'Try to choose the view limits intelligently'

        if data_max < data_min:
            data_min, data_max = data_max, data_min

        # get the nearest tenth-decade that contains the data

        if data_max > 0:
            logs = np.ceil(np.log10(data_max))
            vmax = np.ceil(data_max / (10**(logs - 1))) * (10**(logs - 1))
        else:
            vmax = 100

        if data_min >= 0:
            vmin = 0
        else:
            logs = np.ceil(np.log10(-1.0 * data_min))
            vmin = np.floor(data_min / (10**(logs - 1))) * (10**(logs - 1))

        return transforms.nonsingular(vmin, vmax)
예제 #57
0
    def autoscale(self):
        'Try to choose the view limits intelligently'
        self.verify_intervals()

        vmin, vmax = self.dataInterval.get_bounds()
        if vmax < vmin:
            vmin, vmax = vmax, vmin

        minpos = self.dataInterval.minpos()

        if minpos <= 0:
            raise RuntimeError('No positive data to plot')
        if vmin <= 0:
            vmin = minpos
        if not is_decade(vmin, self._base):
            vmin = decade_down(vmin, self._base)
        if not is_decade(vmax, self._base): vmax = decade_up(vmax, self._base)
        if vmin == vmax:
            vmin = decade_down(vmin, self._base)
            vmax = decade_up(vmax, self._base)
        return mtrans.nonsingular(vmin, vmax)
예제 #58
0
 def view_limits(self, dmin, dmax):
     # begin partial duplication of MaxNLocator.view_limits
     if self._symmetric:
         maxabs = max(abs(dmin), abs(dmax))
         dmin = -maxabs
         dmax = maxabs
     dmin, dmax = mtransforms.nonsingular(dmin, dmax, expander=0.05)
     # end duplication
     margin = self._margin * (dmax - dmin)  # fraction of data range
     vmin = dmin - margin  # expand the view
     vmax = dmax + margin
     bin_boundaries = self.bin_boundaries(vmin, vmax)
     # locate ticks with MaxNLocator
     # Note: If the lines below change vmin or vmax, the bin boundaries
     # later calculated by MaxNLocator.__call__ may differ from those
     # calculated here.
     vmin = min(vmin, max(bin_boundaries[bin_boundaries <= dmin]))
     # expand view to the highest tick below or touching the data
     vmax = max(vmax, min(bin_boundaries[bin_boundaries >= dmax]))
     # expand view to the lowest tick above or touching the data
     return np.array([vmin, vmax])
예제 #59
0
    def autoscale(self):
        'Try to choose the view limits intelligently'
        self.verify_intervals()
        vmin, vmax = self.dataInterval.get_bounds()

        if vmax < vmin:
            vmin, vmax = vmax, vmin

        if vmin == vmax:
            vmin -= 1
            vmax += 1

        exponent, remainder = divmod(math.log10(vmax - vmin), 1)

        if remainder < 0.5:
            exponent -= 1
        scale = 10**(-exponent)
        vmin = math.floor(scale * vmin) / scale
        vmax = math.ceil(scale * vmax) / scale

        return mtransforms.nonsingular(vmin, vmax)