import numpy as np from numpy.random import randn import pandas as pd import seaborn as sns import matplotlib.pyplot as plt from mpld3 import display_d3 np.random.seed(0) def sinplot(flip=1): x = np.linspace(0, 14, 100) for i in range(1, 7): plt.plot(x, np.sin(x + i * .5) * (7 - i) * flip) x1 = randn(80) x2 = randn(80) x3 = x1 * x2 y1 = .5 + 2 * x1 - x2 + 2.5 * x3 + 3 * randn(80) y2 = .5 + 2 * x1 - x2 + 2.5 * randn(80) y3 = y2 + randn(80) g = np.random.choice(list("ABC"), 80) y_logistic = 1 / (1 + np.exp(-y1)) y_flip = [np.random.binomial(1, p) for p in y_logistic] df = pd.DataFrame(dict(x1=x1, x2=x2, x3=x3, y1=y1, y2=y2, y3=y3, y_flip=y_flip, g=g)) d = randn(100, 30) sinplot() sinplot() display_d3() sns.set(style="whitegrid") sinplot() sinplot() display_d3() sns.set(style="nogrid") sinplot() sinplot() display_d3() sns.set() sns.lmplot("x1", "y2", df) fig = plt.gcf() display_d3(fig) sns.lmplot("x1", "y2", df, col="g", size=3.5) fig = plt.gcf() display_d3(fig) sns.lmplot("x1", "y2", df, color="g") fig = plt.gcf() display_d3(fig) sns.regplot("x1", "y1", df) fig = plt.gcf() display_d3(fig) sns.coefplot("y1 ~ x1 * x2 + g", df) fig = plt.gcf() display_d3(fig) sns.interactplot("x1", "x2", "y1", df) fig = plt.gcf() display_d3(fig) sns.corrplot(df) fig = plt.gcf() display_d3(fig) sns.boxplot(df.x1, df.g) fig = plt.gcf() display_d3(fig) sns.violinplot(df.x1, df.g) fig = plt.gcf() display_d3(fig) sns.distplot(df.x1) fig = plt.gcf() display_d3(fig) sns.kdeplot(df.x1, shade=True) fig = plt.gcf() display_d3(fig) sns.kdeplot(df[["x1", "x2"]]) fig = plt.gcf() display_d3(fig) sns.kdeplot(df[["x1", "x2"]], shade=True) fig = plt.gcf() display_d3(fig) def random_walk(n, start=0, p_inc=.2): return start + np.cumsum(np.random.uniform(size=n) < p_inc) starts = np.random.choice(range(4), 10) probs = [.1, .3, .5] walks = np.dstack([[random_walk(15, s, p) for s in starts] for p in probs]) sns.tsplot(walks) fig = plt.gcf() display_d3(fig) sns.tsplot(walks, err_style="ci_bars") fig = plt.gcf() display_d3(fig) def sine_wave(n_x, obs_err_sd=1.5, tp_err_sd=.3): x = np.linspace(0, (n_x - 1) / 2, n_x) y = np.sin(x) + np.random.normal(0, obs_err_sd) + np.random.normal(0, tp_err_sd, n_x) return y sines = np.array([sine_wave(31) for _ in range(20)]) sns.tsplot(sines, err_style="boot_traces", n_boot=500) fig = plt.gcf() display_d3(fig) sns.tsplot(sines, err_style="boot_kde", n_boot=500) fig = plt.gcf() display_d3(fig)