def setup_labels(self, x, *args, **kwargs): s = Continuous().label(*args, **kwargs)._setup(x, Coordinate()) a = PseudoAxis(s._matplotlib_scale) a.set_view_interval(0, 1) locs = a.major.locator() return a, locs
def test_tick_upto(self, x): for n in [2, 5, 10]: s = Continuous().tick(upto=n).setup(x, Coordinate()) a = PseudoAxis(s.matplotlib_scale) a.set_view_interval(0, 1) assert len(a.major.locator()) <= (n + 1)
def test_tick_count(self, x): n = 8 s = Continuous().tick(count=n).setup(x, Coordinate()) a = PseudoAxis(s.matplotlib_scale) a.set_view_interval(0, 1) assert_array_equal(a.major.locator(), np.linspace(0, 1, n))
def test_tick_at(self, x): locs = [.2, .5, .9] s = Continuous().tick(at=locs).setup(x, Coordinate()) a = PseudoAxis(s.matplotlib_scale) a.set_view_interval(0, 1) assert_array_equal(a.major.locator(), locs)
def test_tick_locator(self, t): locator = mpl.dates.YearLocator(month=3, day=15) s = Temporal().tick(locator) a = PseudoAxis(s._setup(t, Coordinate())._matplotlib_scale) a.set_view_interval(0, 365) assert 73 in a.major.locator()
def test_tick_every(self, x): for d in [.05, .2, .5]: s = Continuous().tick(every=d).setup(x, Coordinate()) a = PseudoAxis(s.matplotlib_scale) a.set_view_interval(0, 1) assert np.allclose(np.diff(a.major.locator()), d)
def test_label_base_from_transform(self, x): s = Continuous(trans="log") a = PseudoAxis(s._setup(x, Coordinate())._matplotlib_scale) a.set_view_interval(10, 1000) label, = a.major.formatter.format_ticks([100]) assert r"10^{2}" in label
def test_log_tick_default(self, x): s = Continuous(trans="log")._setup(x, Coordinate()) a = PseudoAxis(s._matplotlib_scale) a.set_view_interval(.5, 1050) ticks = a.major.locator() assert np.allclose(np.diff(np.log10(ticks)), 1)
def test_tick_count_between(self, x): n = 5 lo, hi = .2, .7 s = Continuous().tick(count=n, between=(lo, hi)).setup(x, Coordinate()) a = PseudoAxis(s.matplotlib_scale) a.set_view_interval(0, 1) assert_array_equal(a.major.locator(), np.linspace(lo, hi, n))
def test_label_formatter(self, t): formatter = mpl.dates.DateFormatter("%Y") s = Temporal().label(formatter) a = PseudoAxis(s._setup(t, Coordinate())._matplotlib_scale) a.set_view_interval(10, 1000) label, = a.major.formatter.format_ticks([100]) assert label == "1970"
def test_tick_locator(self, x): locs = [.2, .5, .8] locator = mpl.ticker.FixedLocator(locs) s = Continuous().tick(locator).setup(x, Coordinate()) a = PseudoAxis(s.matplotlib_scale) a.set_view_interval(0, 1) assert_array_equal(a.major.locator(), locs)
def test_tick_every_between(self, x): lo, hi = .2, .8 for d in [.05, .2, .5]: s = Continuous().tick(every=d, between=(lo, hi)).setup(x, Coordinate()) a = PseudoAxis(s.matplotlib_scale) a.set_view_interval(0, 1) expected = np.arange(lo, hi + d, d) assert_array_equal(a.major.locator(), expected)
def test_log_tick_count(self, x): with pytest.raises(RuntimeError, match="`count` requires"): Continuous(trans="log").tick(count=4) s = Continuous(trans="log").tick(count=4, between=(1, 1000)) a = PseudoAxis(s._setup(x, Coordinate())._matplotlib_scale) a.set_view_interval(.5, 1050) assert_array_equal(a.major.locator(), [1, 10, 100, 1000])
def test_tick_minor(self, x): n = 3 s = Continuous().tick(count=2, minor=n).setup(x, Coordinate()) a = PseudoAxis(s.matplotlib_scale) a.set_view_interval(0, 1) # I am not sure why matplotlib's minor ticks include the # largest major location but exclude the smalllest one ... expected = np.linspace(0, 1, n + 2)[1:] assert_array_equal(a.minor.locator(), expected)
def test_symlog_tick_default(self, x): s = Continuous(trans="symlog")._setup(x, Coordinate()) a = PseudoAxis(s._matplotlib_scale) a.set_view_interval(-1050, 1050) ticks = a.major.locator() assert ticks[0] == -ticks[-1] pos_ticks = np.sort(np.unique(np.abs(ticks))) assert np.allclose(np.diff(np.log10(pos_ticks[1:])), 1) assert pos_ticks[0] == 0
def setup_ticks(self, x, *args, **kwargs): s = Continuous().tick(*args, **kwargs)._setup(x, Coordinate()) a = PseudoAxis(s._matplotlib_scale) a.set_view_interval(0, 1) return a
def test_log_tick_upto(self, x): n = 3 s = Continuous(trans="log").tick(upto=n)._setup(x, Coordinate()) a = PseudoAxis(s._matplotlib_scale) assert a.major.locator.numticks == n