import altair_recipes as ar from altair_recipes.common import viz_reg_test from altair_recipes.display_altair 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)
import altair_recipes as ar from altair_recipes.common import viz_reg_test from altair_recipes.display_altair import show_test import numpy as np import pandas as pd #' <h2>Autocorrelation</h2> @viz_reg_test def test_autocorrelation(): np.random.seed(0) data = pd.DataFrame(dict(x=np.random.uniform(size=100))) return ar.autocorrelation(data, column="x", max_lag=15) show_test(test_autocorrelation)
import altair_recipes as ar from altair_recipes.common import viz_reg_test from altair_recipes.display_altair 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)
#' <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.count_heatmap(source, x="IMDB_Rating", y="Rotten_Tomatoes_Rating") show_test(test_count_heatmap)
#' <h2>Scatter</h2> @viz_reg_test def test_scatter(): return ar.scatter( data.iris(), x="petalWidth", y="petalLength", color="sepalWidth", tooltip="species", ) show_test(test_scatter) #' <h2>Multiscatter at defaults</h2> @viz_reg_test def test_multiscatter_defaults(): return ar.multiscatter(data.iris()) show_test(test_multiscatter_defaults) #' <h2>Multiscatter with explicit parameters</h2>
"""Test smoother.""" import altair_recipes as ar from altair_recipes.common import viz_reg_test from altair_recipes.display_altair import show_test import numpy as np import pandas as pd #' <h2>Smoother</h2> @viz_reg_test def test_smoother(): np.random.seed(0) 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)
from altair_recipes.common import viz_reg_test, gather from altair_recipes.display_altair 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(): np.random.seed(0) 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"])