def test_revert_to_default(self): scales = [FixedScale(resolution = 1.0), FixedScale(resolution = 10.0), FixedScale(resolution = 100.0)] ticker = ScaleSystem(*scales) ticks = ticker.ticks(2.0, 3.0, 10) self.check_ticks(ticks, frange(2.0, 3.0, 0.1))
def test_fixed_scales(self): scales = [FixedScale(resolution = 1.0), FixedScale(resolution = 10.0), FixedScale(resolution = 100.0)] ticker = ScaleSystem(default_scale=None, *scales) self.check_ticks(ticker.ticks(5, 35, 3), (10.0, 20.0, 30.0)) self.check_ticks(ticker.ticks(5, 35, 20), frange(5.0, 35.0, 1.0)) self.check_ticks(ticker.ticks(5, 614, 10), (100, 200, 300, 400, 500, 600))
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_scale_system(self): scale = ScaleSystem(FixedScale(resolution=1.0), FixedScale(resolution=2.5), FixedScale(resolution=5.0), FixedScale(resolution=10.0), FixedScale(resolution=20.0), FixedScale(resolution=100.0)) test_intervals = ( (1, 100, 200), (1, 100, 80), (1, 100, 40), (1, 100, 20), (1, 100, 5), (1, 10, 100), (1, 10, 50), (1, 10, 20), ) print for start, end, width in test_intervals: labels = scale.labels(start, end, char_width=width) print "(%d,%d)" % (start, end), " avail:", width, print " used:", sum([len(x[1]) for x in labels]), print zip(*labels)[1] return
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))