Пример #1
0
def test_coord_trans_reverse():
    # coord trans can reverse continous and discrete data
    p = (ggplot(df, aes('factor(x)'))
         + geom_bar(aes(fill='factor(z)'), show_legend=False)
         + coord_trans(x='reverse', y='reverse')
         )
    assert p == 'coord_trans_reverse'
Пример #2
0
def test_coord_trans_backtransforms():
    df = pd.DataFrame({'x': [-np.inf, np.inf], 'y': [1, 2]})
    p = (ggplot(df, aes('x', 'y'))
         + geom_line(size=2)
         + xlim(1, 2)
         + coord_trans(x='log10')
         )
    assert p == 'coord_trans_backtransform'
Пример #3
0
def test_adding_list_ggplot():
    lst = [
        geom_point(),
        geom_point(aes('x+1', 'y+1')),
        xlab('x-label'),
        coord_trans()
    ]
    g = ggplot() + lst
    assert len(g.layers) == 2
    assert g.labels['x'] == 'x-label'
    assert isinstance(g.coordinates, coord_trans)
Пример #4
0
def test_coord_trans_groups():
    df = pd.DataFrame({
        'xmin': [0, 2, 4],
        'xmax': [1, 3, 5],
        'ymin': [0, 2, 4],
        'ymax': [1, 3, 5],
        'c': list('abc')
    })

    p = (ggplot(df)
         + geom_rect(
             aes(xmin='xmin', xmax='xmax', ymin='ymin', ymax='ymax', fill='c'))
         + coord_trans()
         )
    assert p == 'coord-trans-groups'
Пример #5
0
def test_inplace_add():
    p = _p = ggplot(df)

    p += aes('x', 'y')
    assert p is _p

    p += geom_point()
    assert p is _p

    p += stat_identity()
    assert p is _p

    p += scale_x_continuous()
    assert p is _p

    with pytest.warns(PlotnineWarning):
        # Warning for; replacing existing scale added above
        p += xlim(0, 10)
        assert p is _p

    p += lims(y=(0, 10))
    assert p is _p

    p += labs(x='x')
    assert p is _p

    p += coord_trans()
    assert p is _p

    p += facet_null()
    assert p is _p

    p += annotate('point', 5, 5, color='red', size=5)
    assert p is _p

    p += guides()
    assert p is _p

    p += theme_gray()
    assert p is _p

    th = _th = theme_gray()
    th += theme(aspect_ratio=1)
    assert th is _th
Пример #6
0
def test_coord_trans():
    df = pd.DataFrame({
        'x': range(10),
        'y': range(10)
    })
    rdf = pd.DataFrame({
        'xmin': [3],
        'xmax': 7,
        'ymin': -np.inf,
        'ymax': np.inf,
    })

    p = (ggplot(df, aes('x', 'y'))
         + geom_point()
         + geom_rect(
             data=rdf,
             mapping=aes(xmin='xmin', xmax='xmax', ymin='ymin', ymax='ymax'),
             alpha=0.2,
             inherit_aes=False)
         + coord_trans()
         )

    assert p == 'coord-trans'
Пример #7
0
def test_coord_trans_se_false():
    # scatter plot with LM fit using log-log coordinates
    p = (ggplot(df_linear_gtz, aes(x='x', y='y_noisy')) + geom_point() +
         coord_trans(x='log10', y='log10') +
         geom_smooth(method='lm', se=False))
    assert p == 'coord_trans_se_false'
Пример #8
0
def test_coord_trans():
    double_trans = trans_new('double', np.square, np.sqrt)
    assert p + coord_trans(y=double_trans) == 'coord_trans'
Пример #9
0
def test_coord_trans():
    double_trans = trans_new('double', np.square, np.sqrt)
    assert p + coord_trans(y=double_trans) == 'coord_trans'
Пример #10
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'