Esempio n. 1
0
import altair_recipes as ar
from altair_recipes.common import viz_reg_test
from altair_recipes.display_pweave import show_test
import numpy as np
import pandas as pd

#' <h2>Qqplot</h2>


@viz_reg_test
def test_qqplot():

    df = pd.DataFrame({
        "Trial A": np.random.normal(0, 0.8, 1000),
        "Trial B": np.random.normal(-2, 1, 1000),
        "Trial C": np.random.uniform(3, 2, 1000),
    })
    return ar.qqplot(df, x="Trial A", y="Trial C")


show_test(test_qqplot)
Esempio n. 2
0
"""Test smoother."""
import altair_recipes as ar
from altair_recipes.common import viz_reg_test
from altair_recipes.display_pweave import show_test
import numpy as np
import pandas as pd


#' <h2>Smoother</h2>


@viz_reg_test
def test_smoother():
    x = np.random.uniform(size=100)
    data = pd.DataFrame(dict(x=x, y=np.random.uniform(size=100) + 10 * x))
    return ar.smoother(data, *list(data.columns))


show_test(test_smoother)
Esempio n. 3
0
#     return ar.autoplot(data.head({nrows}), columns={vars})
#
# show_test(test_autoplot_{n})
# """.format(
#                     nrows=nrows, vars=vars, n=n
#                 )
#             )
#'  <h3> Test autoplot #1</h3>


@viz_reg_test
def test_autoplot_1():
    return ar.autoplot(data.head(10), columns=["x"])


show_test(test_autoplot_1)

#'  <h3> Test autoplot #2</h3>


@viz_reg_test
def test_autoplot_2():
    return ar.autoplot(data.head(50), columns=["x"])


show_test(test_autoplot_2)

#'  <h3> Test autoplot #3</h3>


@viz_reg_test
Esempio n. 4
0
import altair_recipes as ar
from altair_recipes.common import viz_reg_test
from altair_recipes.display_pweave import show_test
from vega_datasets import data

#' <h2>Lineplot</h2>


@viz_reg_test
def test_lineplot():
    return ar.lineplot(data.iowa_electricity(),
                       x="year",
                       y="net_generation",
                       color="source")


show_test(test_lineplot)
Esempio n. 5
0
#' <h2>Scatterplot</h2>


@viz_reg_test
def test_scatterplot():
    return ar.scatterplot(
        data.iris(),
        x="petalWidth",
        y="petalLength",
        color="sepalWidth",
        tooltip="species",
    )


show_test(test_scatterplot)


#'<h2>Scatterplot alternate data syntax</h2>


@viz_reg_test
def test_scatterplot_alternate_data():
    d = data.iris()
    return ar.scatterplot(
        x=d["petalWidth"],
        y=d["petalLength"],
        color=d["sepalWidth"],
        tooltip=d["species"],
    )
Esempio n. 6
0
import altair_recipes as ar
from altair_recipes.common import viz_reg_test
from altair_recipes.display_pweave import show_test
from vega_datasets import data

#' <h2>Barchart</h2>


@viz_reg_test
def test_barchart_color():
    source = data.barley()
    return ar.barchart(source, x="year", y="mean(yield)", color=True)


show_test(test_barchart_color)
Esempio n. 7
0
import altair_recipes as ar
from altair_recipes.common import viz_reg_test
from altair_recipes.display_pweave import show_test
import numpy as np
import pandas as pd


#' <h2>Stripplot</h2>


@viz_reg_test
def test_stripplot():
    x = np.array(range(100)) // 10
    data = pd.DataFrame(dict(x=x, y=np.random.normal(size=len(x))))

    return ar.stripplot(data)


show_test(test_stripplot)
Esempio n. 8
0
#' <h2>Heatmap</h2>


@viz_reg_test
def test_heatmap():
    # Compute x^2 + y^2 across a 2D grid
    x, y = np.meshgrid(range(-5, 6), range(-5, 6))
    z = x**2 + y**2

    # Convert this grid to columnar data expected by Altair
    data = pd.DataFrame({"x": x.ravel(), "y": y.ravel(), "z": z.ravel()})

    return ar.heatmap(data, x="x", y="y", color="z")


show_test(test_heatmap)

#' <h2>Count Heatmap</h2>


@viz_reg_test
def test_count_heatmap():
    source = data.movies.url
    return ar.heatmap(source,
                      x="IMDB_Rating",
                      y="Rotten_Tomatoes_Rating",
                      color="",
                      aggregate="count")


show_test(test_count_heatmap)
Esempio n. 9
0
import altair as alt
import altair_recipes as ar
from altair_recipes.common import viz_reg_test
from altair_recipes.display_pweave import show_test
from vega_datasets import data

#' <h2>Areaplot</h2>


@viz_reg_test
def test_areaplot():
    return alt.vconcat(*map(
        lambda stack: ar.areaplot(
            data.iowa_electricity(),
            x="year",
            y="net_generation",
            color="source",
            stack=stack,
        ),
        ar.StackType,
    ))


show_test(test_areaplot)
Esempio n. 10
0
import altair_recipes as ar
from altair_recipes.common import viz_reg_test, gather
from altair_recipes.display_pweave import show_test
import numpy as np
import pandas as pd
from vega_datasets import data

#' <h2>Histogram</h2>


@viz_reg_test
def test_histogram():
    return ar.histogram(data.movies(), column="IMDB_Rating")


show_test(test_histogram)

#' <h2>Layered Histogram from wide data</h2>


@viz_reg_test
def test_layered_histogram_wide():
    df = pd.DataFrame({
        "Trial A": np.random.normal(0, 0.8, 1000),
        "Trial B": np.random.normal(-2, 1, 1000),
        "Trial C": np.random.normal(3, 2, 1000),
    })
    return ar.layered_histogram(df, columns=["Trial A", "Trial B", "Trial C"])


show_test(test_layered_histogram_wide)
Esempio n. 11
0
import altair_recipes as ar
from altair_recipes.common import viz_reg_test
from altair_recipes.display_pweave import show_test
import numpy as np
import pandas as pd


#' <h2>Autocorrelation</h2>


@viz_reg_test
def test_autocorrelation():
    data = pd.DataFrame(dict(x=np.random.uniform(size=100)))
    return ar.autocorrelation(data, column="x", max_lag=15)


show_test(test_autocorrelation)
Esempio n. 12
0
import altair_recipes as ar
from altair_recipes.common import viz_reg_test
from altair_recipes.display_pweave import show_test
from vega_datasets import data

#' <h2>Boxplot from melted data</h2>


@viz_reg_test
def test_boxplot_melted():
    return ar.boxplot(data.iris(), columns=["petalLength"], group_by="species")


show_test(test_boxplot_melted)

#' <h2>Boxplot from cast data</h2>


@viz_reg_test
def test_boxplot_cast():
    iris = data.iris()
    return ar.boxplot(iris, columns=list(iris.columns[:-1]))


show_test(test_boxplot_cast)

#' <h2>Boxplot with color</h2>


@viz_reg_test
def test_boxplot_color():