Example #1
0
 def test_format_small_numbers(self):
     fmt = BasicFormatter()
     numlabels = 8
     # test with small numbers
     scale = FixedScale(resolution=1e-4)
     start, end = 5e-5, 8.5e-4
     ticks = scale.ticks(start, end, numlabels)
     labels = fmt.format(ticks, numlabels, None)
     desired = [str(float(i)) + "e-4" for i in range(1, 9)]
     self.check_labels(labels, desired)
Example #2
0
 def test_format_small_numbers(self):
     fmt = BasicFormatter()
     numlabels = 8
     # test with small numbers
     scale = FixedScale(resolution = 1e-4)
     start, end = 5e-5, 8.5e-4
     ticks = scale.ticks(start, end, numlabels)
     labels = fmt.format(ticks, numlabels, None)
     desired = [str(float(i))+"e-4" for i in range(1, 9)]
     self.check_labels(labels, desired)
Example #3
0
    def test_format(self):
        fmt = BasicFormatter()

        # test with a fixed scale
        scale = FixedScale(resolution=1.0)
        start, end = 12.0, 18.0
        numlabels = 8

        ticks = scale.ticks(start, end, numlabels)
        labels = fmt.format(ticks, numlabels, None)
        # desired = [str(float(x)) for x in range(12, 19)]
        ## This test fails when desired is created with str(float(x)).
        ## The format function returns "12",...,"18", not "12.0",...,"18.0".
        desired = ["12", "13", "14", "15", "16", "17", "18"]
        self.check_labels(labels, desired)
Example #4
0
    def test_format(self):
        fmt = BasicFormatter()

        # test with a fixed scale
        scale = FixedScale(resolution = 1.0)
        start, end = 12.0, 18.0
        numlabels = 8

        ticks = scale.ticks(start, end, numlabels)
        labels = fmt.format(ticks, numlabels, None)
        # desired = [str(float(x)) for x in range(12, 19)]
        ## This test fails when desired is created with str(float(x)).
        ## The format function returns "12",...,"18", not "12.0",...,"18.0".
        desired = ["12","13","14","15","16","17","18"]
        self.check_labels(labels, desired)
Example #5
0
    def test2_nice_sci(self):

        # The table of numerical values and their proper representation
        # given a certain number of mantissa digits
        vals = [ (3.14159e10, (2, "3e10"), (3, '3.1e10'), (5, '3.141e10')),
                 (123456789, (3, '1.2e8'), (5, '1.234e8')),
                 (-123456, (2, "-1e5"), (3, "-1e5"), (4, "-1.2e5")),
                 (123, (2, "1e2"), (3, "1.2e2"), (4, "1.23e2")),
                 (1.234, (2, "1"), (3, "1.2"), (4, "1.23")),
                 ]
        fmt = BasicFormatter()
        for lst in vals:
            val = lst[0]
            for mdigits, desired in lst[1:]:
                s = fmt._nice_sci(val, mdigits)
                if s != desired:
                    print "Mismatch for", val, "; desired:", desired, "actual:", s
Example #6
0
    def test2_nice_sci(self):

        # The table of numerical values and their proper representation
        # given a certain number of mantissa digits
        vals = [ (3.14159e10, (2, "3e10"), (3, '3.1e10'), (5, '3.141e10')),
                 (123456789, (3, '1.2e8'), (5, '1.234e8')),
                 (-123456, (2, "-1e5"), (3, "-1e5"), (4, "-1.2e5")),
                 (123, (2, "1e2"), (3, "1.2e2"), (4, "1.23e2")),
                 (1.234, (2, "1"), (3, "1.2"), (4, "1.23")),
                 ]
        fmt = BasicFormatter()
        for lst in vals:
            val = lst[0]
            for mdigits, desired in lst[1:]:
                s = fmt._nice_sci(val, mdigits)
                if s != desired:
                    print "Mismatch for", val, "; desired:", desired, "actual:", s
Example #7
0
    def test_estimate_default_scale(self):
        fmt = BasicFormatter()
        scale = DefaultScale()

        # Test using numlabels
        test_intervals = ((12., 18., 8),
                          (-4., 16., 10),
                          (5e-5, 8.5e-4, 8),
                          (3e8, 6e8, 8),
                          )
        for start, end, numlabels in test_intervals:
            estimate = fmt.estimate_width(start, end, numlabels, ticker=scale)[1]
            ticks = scale.ticks(start, end, numlabels)
            labels = fmt.format(ticks, numlabels, None)
            actual = sum(map(len, labels))
            err = abs(estimate - actual) / actual
            self.assertLess(err, 0.5)
        return
Example #8
0
    def test_estimate_default_scale(self):
        fmt = BasicFormatter()
        scale = DefaultScale()

        # Test using numlabels
        test_intervals = ((12., 18., 8),
                          (-4., 16., 10),
                          (5e-5, 8.5e-4, 8),
                          (3e8, 6e8, 8),
                          )
        for start, end, numlabels in test_intervals:
            estimate = fmt.estimate_width(start, end, numlabels, ticker=scale)[1]
            ticks = scale.ticks(start, end, numlabels)
            labels = fmt.format(ticks, numlabels, None)
            actual = sum(map(len, labels))
            err = abs(estimate - actual) / actual
            self.assertLess(err, 0.5)
        return
Example #9
0
 def __init__(self, formatter=None):
     if formatter is None:
         formatter = BasicFormatter()
     self.formatter = formatter
Example #10
0
 def __init__(self, resolution, zero=0.0, formatter=None):
     self.resolution = resolution
     self.zero = zero
     if formatter is None:
         formatter = BasicFormatter()
     self.formatter = formatter