示例#1
0
    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
示例#2
0
    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)
示例#3
0
    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
示例#4
0
    def test_coordinate_numeric_data(self, y):

        ax = mpl.figure.Figure().subplots()
        s = Nominal()._setup(y, Coordinate(), ax.yaxis)
        assert_array_equal(s(y), np.array([1, 0, 2, 0], float))
        f = ax.yaxis.get_major_formatter()
        assert f.format_ticks([0, 1, 2]) == ["-1.5", "1.0", "3.0"]
示例#5
0
    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()
示例#6
0
    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)
示例#7
0
    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))
示例#8
0
    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)
示例#9
0
    def test_tick_upto(self, t, x):

        n = 8
        ax = mpl.figure.Figure().subplots()
        Temporal().tick(upto=n)._setup(t, Coordinate(), ax.xaxis)
        locator = ax.xaxis.get_major_locator()
        assert set(locator.maxticks.values()) == {n}
示例#10
0
    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)
示例#11
0
    def test_coordinate_axis(self, x):

        ax = mpl.figure.Figure().subplots()
        s = Nominal()._setup(x, Coordinate(), ax.xaxis)
        assert_array_equal(s(x), np.array([0, 1, 2, 1], float))
        f = ax.xaxis.get_major_formatter()
        assert f.format_ticks([0, 1, 2]) == ["a", "c", "b"]
示例#12
0
    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))
示例#13
0
    def test_coordinate_axis_with_subset_order(self, x):

        order = ["c", "a"]
        ax = mpl.figure.Figure().subplots()
        s = Nominal(order=order)._setup(x, Coordinate(), ax.xaxis)
        assert_array_equal(s(x), np.array([1, 0, np.nan, 0], float))
        f = ax.xaxis.get_major_formatter()
        assert f.format_ticks([0, 1, 2]) == [*order, ""]
示例#14
0
    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)
示例#15
0
    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"
示例#16
0
    def test_coordinate_numeric_data_with_order(self, y):

        order = [1, 4, -1.5]
        ax = mpl.figure.Figure().subplots()
        s = Nominal(order=order)._setup(y, Coordinate(), ax.yaxis)
        assert_array_equal(s(y), np.array([0, 2, np.nan, 2], float))
        f = ax.yaxis.get_major_formatter()
        assert f.format_ticks([0, 1, 2]) == ["1.0", "4.0", "-1.5"]
示例#17
0
    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)
示例#18
0
    def test_coordinate_axis(self, t, x):

        ax = mpl.figure.Figure().subplots()
        s = Temporal()._setup(t, Coordinate(), ax.xaxis)
        assert_array_equal(s(t), x)
        locator = ax.xaxis.get_major_locator()
        formatter = ax.xaxis.get_major_formatter()
        assert isinstance(locator, mpl.dates.AutoDateLocator)
        assert isinstance(formatter, mpl.dates.AutoDateFormatter)
示例#19
0
    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])
示例#20
0
    def test_coordinate_axis_with_category_dtype(self, x):

        order = ["b", "a", "d", "c"]
        x = x.astype(pd.CategoricalDtype(order))
        ax = mpl.figure.Figure().subplots()
        s = Nominal()._setup(x, Coordinate(), ax.xaxis)
        assert_array_equal(s(x), np.array([1, 3, 0, 3], float))
        f = ax.xaxis.get_major_formatter()
        assert f.format_ticks([0, 1, 2, 3]) == order
示例#21
0
    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)
示例#22
0
    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
示例#23
0
    def test_coordinate_transform_error(self, x):

        s = Continuous(trans="bad")
        with pytest.raises(ValueError, match="Unknown value provided"):
            s._setup(x, Coordinate())
示例#24
0
    def test_label_concise(self, t, x):

        ax = mpl.figure.Figure().subplots()
        Temporal().label(concise=True)._setup(t, Coordinate(), ax.xaxis)
        formatter = ax.xaxis.get_major_formatter()
        assert isinstance(formatter, mpl.dates.ConciseDateFormatter)
示例#25
0
    def test_coordinate_transform_with_parameter(self, x):

        s = Continuous(trans="pow3")._setup(x, Coordinate())
        assert_series_equal(s(x), np.power(x, 3))
示例#26
0
    def test_coordinate_defaults(self, t, x):

        s = Temporal()._setup(t, Coordinate())
        assert_array_equal(s(t), x)
示例#27
0
    def test_coordinate_transform(self, x):

        s = Continuous(trans="log")._setup(x, Coordinate())
        assert_series_equal(s(x), np.log10(x))
示例#28
0
    def test_coordinate_defaults(self, x):

        s = Continuous()._setup(x, Coordinate())
        assert_series_equal(s(x), x)
示例#29
0
    def test_coordinate_with_subset_order(self, x):

        s = Nominal(order=["c", "a"])._setup(x, Coordinate())
        assert_array_equal(s(x), np.array([1, 0, np.nan, 0], float))
示例#30
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