def test_logn_trans():
    log3_trans = log_trans(3)
    _test_trans(log3_trans, arr)

    log4_trans = log_trans(4, domain=(0.1, 100),
                           breaks=mpl_breaks(),
                           minor_breaks=minor_breaks())
    _test_trans(log4_trans, arr)
Exemple #2
0
def test_trans_minor_breaks():
    class identity_trans(trans):
        def __init__(self):
            self.minor_breaks = trans_minor_breaks(identity_trans)

    class square_trans(trans):
        transform = staticmethod(np.square)
        inverse = staticmethod(np.sqrt)

        def __init__(self):
            self.minor_breaks = trans_minor_breaks(square_trans)

    class weird_trans(trans):
        dataspace_is_numerical = False

        def __init__(self):
            self.minor_breaks = trans_minor_breaks(weird_trans)

    major = [1, 2, 3, 4]
    limits = [0, 5]
    regular_minors = trans().minor_breaks(major, limits)
    npt.assert_allclose(regular_minors,
                        identity_trans().minor_breaks(major, limits))

    # Transform the input major breaks and check against
    # the inverse of the output minor breaks
    squared_input_minors = square_trans().minor_breaks(np.square(major),
                                                       np.square(limits))
    npt.assert_allclose(regular_minors, np.sqrt(squared_input_minors))

    t = weird_trans()
    with pytest.raises(TypeError):
        t.minor_breaks(major)

    # Test minor_breaks for log scales are 2 less than the base
    base = 10
    breaks = np.arange(1, 3)
    limits = [breaks[0], breaks[-1]]
    t = log_trans(base)
    assert len(t.minor_breaks(breaks, limits)) == base - 2

    base = 5  # Odd base
    breaks = np.arange(1, 3)
    limits = [breaks[0], breaks[-1]]
    t = log_trans(base)
    assert len(t.minor_breaks(breaks, limits)) == base - 2

    t = log_trans()
    major = t.transform([1, 10, 100])
    limits = t.transform([1, 100])
    result = trans_minor_breaks(t)(major, limits, n=4)
    npt.assert_allclose(result, [
        1.02961942, 1.5260563, 1.85629799, 2.10413415, 3.33220451, 3.8286414,
        4.15888308, 4.40671925
    ])
Exemple #3
0
def test_trans_minor_breaks():
    class identity_trans(trans):
        def __init__(self):
            self.minor_breaks = trans_minor_breaks(identity_trans)

    class square_trans(trans):
        transform = staticmethod(np.square)
        inverse = staticmethod(np.sqrt)

        def __init__(self):
            self.minor_breaks = trans_minor_breaks(square_trans)

    class weird_trans(trans):
        dataspace_is_numerical = False

        def __init__(self):
            self.minor_breaks = trans_minor_breaks(weird_trans)

    major = [1, 2, 3, 4]
    limits = [0, 5]
    regular_minors = trans().minor_breaks(major, limits)
    npt.assert_allclose(
        regular_minors,
        identity_trans().minor_breaks(major, limits))

    # Transform the input major breaks and check against
    # the inverse of the output minor breaks
    squared_input_minors = square_trans().minor_breaks(
        np.square(major), np.square(limits))
    npt.assert_allclose(regular_minors,
                        np.sqrt(squared_input_minors))

    t = weird_trans()
    with pytest.raises(TypeError):
        t.minor_breaks(major)

    # Test minor_breaks for log scales are 2 less than the base
    base = 10
    breaks = np.arange(1, 3)
    limits = [breaks[0], breaks[-1]]
    t = log_trans(base)
    assert len(t.minor_breaks(breaks, limits)) == base - 2

    base = 5  # Odd base
    breaks = np.arange(1, 3)
    limits = [breaks[0], breaks[-1]]
    t = log_trans(base)
    assert len(t.minor_breaks(breaks, limits)) == base - 2
Exemple #4
0
def test_wrong_bases():
    # x axis not transformed
    p = (ggplot(df, aes('x', 'x')) +
         annotation_logticks(sides='b', size=.75, base=10) + geom_point())

    with pytest.warns(PlotnineWarning):
        p.draw_test()

    # x axis not transform, but ticks requested for a different base
    p = (ggplot(df, aes('x', 'x')) +
         annotation_logticks(sides='b', size=.75, base=10) +
         scale_x_continuous(trans=log_trans(8)) + geom_point())

    with pytest.warns(PlotnineWarning):
        p.draw_test()

    # x axis is discrete
    df2 = df.assign(discrete=pd.Categorical([str(a) for a in df['x']]))
    p = (ggplot(df2, aes('discrete', 'x')) +
         annotation_logticks(sides='b', size=.75, base=None) + geom_point())

    with pytest.warns(PlotnineWarning):
        p.draw_test()

    # y axis is discrete
    df2 = df.assign(discrete=pd.Categorical([str(a) for a in df['x']]))
    p = (ggplot(df2, aes('x', 'discrete')) +
         annotation_logticks(sides='l', size=.75, base=None) + geom_point())

    with pytest.warns(PlotnineWarning):
        p.draw_test()
def test_trans_minor_breaks():
    class identity_trans(trans):
        def __init__(self):
            self.minor_breaks = trans_minor_breaks(identity_trans)

    class square_trans(trans):
        transform = staticmethod(np.square)
        inverse = staticmethod(np.sqrt)

        def __init__(self):
            self.minor_breaks = trans_minor_breaks(square_trans)

    class weird_trans(trans):
        dataspace_is_numerical = False

        def __init__(self):
            self.minor_breaks = trans_minor_breaks(weird_trans)

    major = [1, 2, 3, 4]
    limits = [0, 5]
    regular_minors = trans().minor_breaks(major, limits)
    npt.assert_allclose(regular_minors,
                        identity_trans().minor_breaks(major, limits))

    # Transform the input major breaks and check against
    # the inverse of the output minor breaks
    squared_input_minors = square_trans().minor_breaks(np.square(major),
                                                       np.square(limits))
    npt.assert_allclose(regular_minors, np.sqrt(squared_input_minors))

    t = weird_trans()
    with pytest.raises(TypeError):
        t.minor_breaks(major)

    # Test minor_breaks for log scales are 2 less than the base
    base = 10
    breaks = np.arange(1, 3)
    limits = [breaks[0], breaks[-1]]
    t = log_trans(base)
    assert len(t.minor_breaks(breaks, limits)) == base - 2

    base = 5  # Odd base
    breaks = np.arange(1, 3)
    limits = [breaks[0], breaks[-1]]
    t = log_trans(base)
    assert len(t.minor_breaks(breaks, limits)) == base - 2
Exemple #6
0
def test_annotation_logticks_base_8():
    base = 8
    df = pd.DataFrame({'x': base**np.arange(4)})
    # The grid should align with the logticks
    p = (ggplot(df, aes('x', 'x')) + annotation_logticks(sides='b', size=.75) +
         geom_point() + scale_x_continuous(trans=log_trans(base=base)) +
         theme(panel_grid_minor=element_line(color='green'),
               panel_grid_major=element_line(color='red')))

    assert p == 'annotation_logticks_base_8'
Exemple #7
0
def test_wrong_bases():
    # x axis not transformed
    p = (ggplot(df, aes('x', 'x'))
         + annotation_logticks(sides='b', size=.75, base=10)
         + geom_point()
         )

    with pytest.warns(PlotnineWarning):
        p.draw_test()

    # x axis not transform, but ticks requested for a different base
    p = (ggplot(df, aes('x', 'x'))
         + annotation_logticks(sides='b', size=.75, base=10)
         + scale_x_continuous(trans=log_trans(8))
         + geom_point()
         )

    with pytest.warns(PlotnineWarning):
        p.draw_test()