コード例 #1
0
ファイル: test_plotting.py プロジェクト: wenliangz/pdvega
def test_lag_plot(lag):
    data = pd.DataFrame({'x': range(10), 'y': range(10)})

    # test series input
    plot = pdvega.lag_plot(data['x'], lag=lag)
    lag_data = utils.get_data(plot)

    spec = plot.to_dict()
    assert spec['mark'] == 'point'
    assert spec['encoding']['x']['type'] == 'quantitative'
    assert spec['encoding']['y']['type'] == 'quantitative'

    utils.check_encodings(plot, x='y(t)', y='y(t + {0})'.format(lag))
    assert lag_data.shape == (data.shape[0] - lag, 2)

    # test dataframe input
    plot = pdvega.lag_plot(data, lag=lag)
    lag_data = utils.get_data(plot)
    spec = plot.to_dict()

    assert spec['mark'] == 'point'
    assert spec['encoding']['x']['type'] == 'quantitative'
    assert spec['encoding']['y']['type'] == 'quantitative'
    assert spec['encoding']['color']['type'] == 'nominal'
    utils.check_encodings(plot,
                          x='y(t)',
                          y='y(t + {0})'.format(lag),
                          color='variable')
    assert lag_data.shape == (2 * (data.shape[0] - lag), 3)
コード例 #2
0
def test_parallel_coordinates():
    data = pd.DataFrame({'x': range(10),
                         'y': range(10),
                         'z': range(10),
                         'c': list('ABABABABAB')})
    plot = pdvega.parallel_coordinates(data, 'c', alpha=0.5)
    utils.validate_vegalite(plot.spec)
    utils.check_encodings(plot.spec, x='variable', y='value',
                          color='c', detail='index', opacity=utils.IGNORE)
    enc = plot.spec['encoding']
    assert plot.spec['mark'] == 'line'
    assert enc['x']['type'] == 'nominal'
    assert enc['y']['type'] == 'quantitative'
    assert enc['color']['type'] == 'nominal'
    assert enc['detail']['type'] == 'quantitative'
    assert enc['opacity']['value'] == 0.5
    df = utils.get_data(plot.spec)
    assert set(pd.unique(df['variable'])) == {'x', 'y', 'z'}

    plot = pdvega.parallel_coordinates(data, 'c', cols=['x', 'y'])
    utils.validate_vegalite(plot.spec)
    utils.check_encodings(plot.spec, x='variable', y='value',
                          color='c', detail='index')
    enc = plot.spec['encoding']
    assert plot.spec['mark'] == 'line'
    assert enc['x']['type'] == 'nominal'
    assert enc['y']['type'] == 'quantitative'
    assert enc['color']['type'] == 'nominal'
    assert enc['detail']['type'] == 'quantitative'
    df = utils.get_data(plot.spec)
    assert set(pd.unique(df['variable'])) == {'x', 'y'}
コード例 #3
0
ファイル: test_core.py プロジェクト: nofeetbird0321/pdvega
def test_df_kde_y():
    df = pd.DataFrame({'x': range(10), 'y': range(10)})
    plot = df.vgplot.kde(y='y', bw_method='scott')
    assert plot.spec['mark'] == 'line'
    utils.check_encodings(plot.spec, x=' ', y='Density', color=utils.IGNORE)
    data = utils.get_data(plot.spec)
    assert set(pd.unique(data['variable'])) == {'y'}
コード例 #4
0
ファイル: test_plotting.py プロジェクト: wenliangz/pdvega
def test_andrews_curves():
    data = pd.DataFrame({
        'x': range(10),
        'y': range(10),
        'z': range(10),
        'c': list('ABABABABAB')
    })
    n_samples = 120
    n_points = len(data)
    plot = pdvega.andrews_curves(data, 'c', samples=120, alpha=0.5)
    utils.validate_vegalite(plot)
    utils.check_encodings(plot,
                          x='t',
                          y=' ',
                          color='c',
                          detail='sample',
                          opacity=utils.IGNORE)

    spec = plot.to_dict()
    enc = spec['encoding']
    assert spec['mark'] == 'line'
    assert enc['x']['type'] == 'quantitative'
    assert enc['y']['type'] == 'quantitative'
    assert enc['color']['type'] == 'nominal'
    assert enc['detail']['type'] == 'quantitative'
    assert enc['opacity']['value'] == 0.5

    df = utils.get_data(plot)
    assert len(df) == n_samples * n_points
コード例 #5
0
ファイル: test_core.py プロジェクト: nofeetbird0321/pdvega
def test_line_simple():
    df = pd.DataFrame({'x': [1, 4, 2, 3, 5], 'y': [6, 3, 4, 5, 2]})

    plot = df.vgplot.line()
    utils.validate_vegalite(plot.spec)
    assert plot.spec['mark'] == 'line'
    utils.check_encodings(plot.spec, x='index', y='value', color='variable')
    data = utils.get_data(plot.spec)
    assert set(pd.unique(data['variable'])) == {'x', 'y'}
コード例 #6
0
ファイル: test_core.py プロジェクト: nofeetbird0321/pdvega
def test_bar_stacked():
    df = pd.DataFrame({'x': [1, 4, 2, 3, 5], 'y': [6, 3, 4, 5, 2]})

    plot = df.vgplot.bar(stacked=True)
    utils.validate_vegalite(plot.spec)
    assert plot.spec['mark'] == 'bar'
    utils.check_encodings(plot.spec, x='index', y='value', color='variable')
    data = utils.get_data(plot.spec)
    assert set(pd.unique(data['variable'])) == {'x', 'y'}
    assert plot.spec['encoding']['y']['stack'] == "zero"
コード例 #7
0
ファイル: test_core.py プロジェクト: nofeetbird0321/pdvega
def test_df_area_xy_unstacked():
    df = pd.DataFrame({
        'x': [1, 4, 2, 3, 5],
        'y': [6, 3, 4, 5, 2],
        'z': range(5)
    })

    plot = df.vgplot.area(x='x', y='y', stacked=False)
    utils.validate_vegalite(plot.spec)
    assert plot.spec['mark'] == 'area'
    utils.check_encodings(plot.spec, x='x', y='value', color='variable')
    data = utils.get_data(plot.spec)
    assert set(pd.unique(data['variable'])) == {'y'}
    assert plot.spec['encoding']['y']['stack'] is None
コード例 #8
0
ファイル: test_core.py プロジェクト: nofeetbird0321/pdvega
def test_barh_simple():
    df = pd.DataFrame({'x': [1, 4, 2, 3, 5], 'y': [6, 3, 4, 5, 2]})

    plot = df.vgplot.barh()
    utils.validate_vegalite(plot.spec)
    assert plot.spec['mark'] == 'bar'
    utils.check_encodings(plot.spec,
                          y='index',
                          x='value',
                          color='variable',
                          opacity=utils.IGNORE)
    data = utils.get_data(plot.spec)
    assert set(pd.unique(data['variable'])) == {'x', 'y'}
    assert plot.spec['encoding']['x']['stack'] is None
コード例 #9
0
ファイル: test_core.py プロジェクト: nofeetbird0321/pdvega
def test_df_area_unstacked():
    df = pd.DataFrame({'x': [1, 4, 2, 3, 5], 'y': [6, 3, 4, 5, 2]})

    plot = df.vgplot.area(stacked=False)
    utils.validate_vegalite(plot.spec)
    assert plot.spec['mark'] == 'area'
    utils.check_encodings(plot.spec,
                          x='index',
                          y='value',
                          color='variable',
                          opacity=utils.IGNORE)
    data = utils.get_data(plot.spec)
    assert set(pd.unique(data['variable'])) == {'x', 'y'}
    assert plot.spec['encoding']['y']['stack'] is None
    assert plot.spec['encoding']['opacity']['value'] == 0.7