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)
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)
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)
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)
def test_format(self): test_ranges = [(12003, 12015, 1.0), (1.2003, 1.2015, 1e-4), (-1.2015, -1.2003, 1e-4)] for start, end, resol in test_ranges: fmt = OffsetFormatter() fmt.use_offset = True fmt.offset_format = "decimal" fmt.end_label_format = "sci" scale = FixedScale(resolution=resol) numlabels = 12 ticks = scale.ticks(start, end, numlabels) print "range:", start, end labels = fmt.format(ticks, numlabels, None) print "Labels:", labels, "\n" print "estimated width:", fmt.estimate_width(start, end, numlabels) print "actual width:", sum(map(len, labels))
def test_format(self): test_ranges = [(12003, 12015, 1.0), (1.2003, 1.2015, 1e-4), (-1.2015, -1.2003, 1e-4)] for start, end, resol in test_ranges: fmt = OffsetFormatter() fmt.use_offset=True fmt.offset_format = "decimal" fmt.end_label_format = "sci" scale = FixedScale(resolution = resol) numlabels = 12 ticks = scale.ticks(start, end, numlabels) print "range:", start, end labels = fmt.format(ticks, numlabels, None) print "Labels:", labels, "\n" print "estimated width:", fmt.estimate_width(start, end, numlabels) print "actual width:", sum(map(len, labels))