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
def test_scatter_common_columns(): df = pd.DataFrame({'x': [1, 4, 2, 3, 5], 'y': [6, 3, 4, 5, 2]}) plot = df.vgplot.scatter(x='x', y='y', c='y') utils.validate_vegalite(plot.spec) assert plot.spec['mark'] == 'circle' utils.check_encodings(plot.spec, x='x', y='y', color='y')
def test_scatter_common_columns(): df = pd.DataFrame({"x": [1, 4, 2, 3, 5], "y": [6, 3, 4, 5, 2]}) plot = df.vgplot.scatter(x="x", y="y", c="y") utils.validate_vegalite(plot) assert plot.mark == "point" utils.check_encodings(plot, x="x", y="y", color="y")
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'}
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'}
def test_barh_xy(): df = pd.DataFrame({"x": [1, 4, 2, 3, 5], "y": [6, 3, 4, 5, 2]}) plot = df.vgplot.barh(x="x", y="y") utils.validate_vegalite(plot) assert plot.mark == "bar" utils.check_encodings(plot, x="value", y="x", color="variable") data = plot.data assert set(pd.unique(data["variable"])) == {"y"} assert plot["encoding"]["x"]["stack"] is None
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) assert plot.mark == "bar" utils.check_encodings(plot, x="index", y="value", color="variable") data = plot.data assert set(pd.unique(data["variable"])) == {"x", "y"} assert plot["encoding"]["y"]["stack"] == "zero"
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"
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) assert plot.mark == "line" utils.check_encodings(plot, x="index", y="value", color="variable") data = plot.data assert set(pd.unique(data["variable"])) == {"x", "y"}
def test_scatter_color_size(): df = pd.DataFrame({ 'x': [1, 4, 2, 3, 5], 'y': [6, 3, 4, 5, 2], 'c': range(5), 's': range(5) }) plot = df.vgplot.scatter(x='x', y='y', c='c', s='s') utils.validate_vegalite(plot.spec) assert plot.spec['mark'] == 'circle' utils.check_encodings(plot.spec, x='x', y='y', color='c', size='s')
def test_scatter_color_size(): df = pd.DataFrame({ "x": [1, 4, 2, 3, 5], "y": [6, 3, 4, 5, 2], "c": range(5), "s": range(5) }) plot = df.vgplot.scatter(x="x", y="y", c="c", s="s") utils.validate_vegalite(plot) assert plot.mark == "point" utils.check_encodings(plot, x="x", y="y", color="c", size="s")
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
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
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) assert plot.mark == "area" utils.check_encodings(plot, x="x", y="value", color="variable") data = plot.data assert set(pd.unique(data["variable"])) == {"y"} assert plot["encoding"]["y"]["stack"] is None
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) assert plot.mark == "area" utils.check_encodings(plot, x="index", y="value", color="variable", opacity=utils.IGNORE) data = plot.data assert set(pd.unique(data["variable"])) == {"x", "y"} assert plot["encoding"]["y"]["stack"] is None assert plot["encoding"]["opacity"]["value"] == 0.7
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
def test_scatter_matrix(): df = pd.DataFrame({'x': range(5), 'y': range(5), 'label': list('ABABA')}) # no color or size specified plot = pdvega.scatter_matrix(df) utils.validate_vegalite(plot) spec = plot.to_dict() assert spec['repeat']['row'] == ['x', 'y'] assert spec['repeat']['column'] == ['y', 'x'] assert spec['spec']['encoding']['color']['condition'][ 'value'] == 'steelblue' # with color specified plot = pdvega.scatter_matrix(df, c='label') utils.validate_vegalite(plot) spec = plot.to_dict() assert spec['repeat']['row'] == ['x', 'y'] assert spec['repeat']['column'] == ['y', 'x'] assert spec['spec']['encoding']['color']['condition']['field'] == 'label' # with size specified plot = pdvega.scatter_matrix(df, s='label') utils.validate_vegalite(plot) spec = plot.to_dict() assert spec['repeat']['row'] == ['x', 'y'] assert spec['repeat']['column'] == ['y', 'x'] assert spec['spec']['encoding']['color']['condition'][ 'value'] == 'steelblue' assert spec['spec']['encoding']['size']['field'] == 'label' # test figsize keyword figsize = (8, 6) dpi = 40 ncols = 2 plot = pdvega.scatter_matrix(df, figsize=figsize, dpi=dpi) utils.validate_vegalite(plot) spec = plot.to_dict() assert np.allclose(spec['spec']['width'], 0.8 * dpi * figsize[0] / ncols) assert np.allclose(spec['spec']['height'], 0.8 * dpi * figsize[1] / ncols)
def test_series_barh(): ser = pd.Series([4, 5, 4, 5], index=["A", "B", "C", "D"]) plot = ser.vgplot.barh() utils.validate_vegalite(plot) assert plot.mark == "bar" utils.check_encodings(plot, y="index", x="0")
def test_series_line(): ser = pd.Series([3, 2, 3, 2, 3]) plot = ser.vgplot.line() utils.validate_vegalite(plot.spec) assert plot.spec['mark'] == 'line' utils.check_encodings(plot.spec, x='index', y='0')
def test_series_barh(): ser = pd.Series([4, 5, 4, 5], index=['A', 'B', 'C', 'D']) plot = ser.vgplot.barh() utils.validate_vegalite(plot.spec) assert plot.spec['mark'] == 'bar' utils.check_encodings(plot.spec, y='index', x='0')
def test_series_line(): ser = pd.Series([3, 2, 3, 2, 3]) plot = ser.vgplot.line() utils.validate_vegalite(plot) assert plot.mark == "line" utils.check_encodings(plot, x="index", y="0")