Пример #1
0
def reverse_transform(trans):
    """Take a transform and make it go from high to low
    instead of low to high
    """
    def inverse_breaks(limits):
        return trans.breaks(tuple(sorted(limits)))

    def inverse_minor_breaks(major, limits):
        return trans.minor_breaks(major, tuple(sorted(limits)))

    if trans.__class__.__name__ != 'type':
        name = '-' + trans.__class__.__name__
    else:
        name = '-' + trans.__name__
    if name.endswith('_trans'):
        name = name[:-len('_trans')]
    return trans_new(
        name,
        lambda x: -1 * trans.transform(x),
        lambda x: trans.inverse(np.array(x) * -1),
        breaks=inverse_breaks,
        minor_breaks=inverse_minor_breaks,
        _format=trans.format,
        domain=trans.domain,
    )
Пример #2
0
def test_trans_new():
    t = trans_new('bounded_identity',
                  staticmethod(lambda x: x),
                  classmethod(lambda x: x),
                  _format=lambda x: str(x),
                  domain=(-999, 999),
                  doc='Bounded Identity transform')

    assert t.__name__ == 'bounded_identity_trans'
    assert isinstance(t.transform, FunctionType)
    assert isinstance(t.inverse, MethodType)
    assert isinstance(t.format, FunctionType)
    assert t.domain == (-999, 999)
    assert t.__doc__ == 'Bounded Identity transform'

    # ticks do not go beyond the bounds
    major = t().breaks((-1999, 1999))
    assert min(major) >= -999
    assert max(major) <= 999
Пример #3
0
def test_coord_trans():
    double_trans = trans_new('double', np.square, np.sqrt)
    assert p + coord_trans(y=double_trans) == 'coord_trans'
Пример #4
0
def asinh_trans() -> trans:
    return trans_new("asinh", transform=np.arcsinh, inverse=np.sinh, breaks=asinh_breaks)
Пример #5
0
def test_coord_trans():
    double_trans = trans_new('double', np.square, np.sqrt)
    assert p + coord_trans(y=double_trans) == 'coord_trans'
Пример #6
0
def test_coord_trans():
    double_trans = trans_new('double', np.square, np.sqrt)
    # Warns probably because of a bad value around the left
    # edge of the domain.
    with pytest.warns(RuntimeWarning):
        assert p + coord_trans(y=double_trans) == 'coord_trans'