doc/_tutorial/function_overview.ipynb
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from IPython.display import HTML
sns.set_theme()
penguins = sns.load_dataset("penguins")
sns.histplot(data=penguins, x="flipper_length_mm", hue="species", multiple="stack")
sns.kdeplot(data=penguins, x="flipper_length_mm", hue="species", multiple="stack")
from matplotlib.patches import FancyBboxPatch
f, ax = plt.subplots(figsize=(7, 5))
f.subplots_adjust(0, 0, 1, 1)
ax.set_axis_off()
ax.set(xlim=(0, 1), ylim=(0, 1))
modules = "relational", "distributions", "categorical"
pal = sns.color_palette("deep")
colors = dict(relational=pal[0], distributions=pal[1], categorical=pal[2])
pal = sns.color_palette("dark")
text_colors = dict(relational=pal[0], distributions=pal[1], categorical=pal[2])
functions = dict(
relational=["scatterplot", "lineplot"],
distributions=["histplot", "kdeplot", "ecdfplot", "rugplot"],
categorical=["stripplot", "swarmplot", "boxplot", "violinplot", "pointplot", "barplot"],
)
pad = .06
w = .2
h = .15
xs = np.arange(0, 1, 1 / 3) + pad * 1.05
y = .7
for x, mod in zip(xs, modules):
color = colors[mod] + (.2,)
text_color = text_colors[mod]
box = FancyBboxPatch((x, y), w, h, f"round,pad={pad}", color="white")
ax.add_artist(box)
box = FancyBboxPatch((x, y), w, h, f"round,pad={pad}", linewidth=1, edgecolor=text_color, facecolor=color)
ax.add_artist(box)
ax.text(x + w / 2, y + h / 2, f"{mod[:3]}plot\n({mod})", ha="center", va="center", size=22, color=text_color)
for i, func in enumerate(functions[mod]):
x_i = x + w / 2
y_i = y - i * .1 - h / 2 - pad
box = FancyBboxPatch((x_i - w / 2, y_i - pad / 3), w, h / 4, f"round,pad={pad / 3}",
color="white")
ax.add_artist(box)
box = FancyBboxPatch((x_i - w / 2, y_i - pad / 3), w, h / 4, f"round,pad={pad / 3}",
linewidth=1, edgecolor=text_color, facecolor=color)
ax.add_artist(box)
ax.text(x_i, y_i, func, ha="center", va="center", size=18, color=text_color)
ax.plot([x_i, x_i], [y, y_i], zorder=-100, color=text_color, lw=1)
sns.displot(data=penguins, x="flipper_length_mm", hue="species", multiple="stack")
sns.displot(data=penguins, x="flipper_length_mm", hue="species", multiple="stack", kind="kde")
sns.displot(data=penguins, x="flipper_length_mm", hue="species", col="species")
f, axs = plt.subplots(1, 2, figsize=(8, 4), gridspec_kw=dict(width_ratios=[4, 3]))
sns.scatterplot(data=penguins, x="flipper_length_mm", y="bill_length_mm", hue="species", ax=axs[0])
sns.histplot(data=penguins, x="species", hue="species", shrink=.8, alpha=.8, legend=False, ax=axs[1])
f.tight_layout()
tips = sns.load_dataset("tips")
g = sns.relplot(data=tips, x="total_bill", y="tip")
g.ax.axline(xy1=(10, 2), slope=.2, color="b", dashes=(5, 2))
g = sns.relplot(data=penguins, x="flipper_length_mm", y="bill_length_mm", col="sex")
g.set_axis_labels("Flipper length (mm)", "Bill length (mm)")
f, ax = plt.subplots()
f, ax = plt.subplots(1, 2, sharey=True)
g = sns.FacetGrid(penguins)
g = sns.FacetGrid(penguins, col="sex")
g = sns.FacetGrid(penguins, col="sex", height=3.5, aspect=.75)
sns.jointplot(data=penguins, x="flipper_length_mm", y="bill_length_mm", hue="species")
sns.pairplot(data=penguins, hue="species")
sns.jointplot(data=penguins, x="flipper_length_mm", y="bill_length_mm", hue="species", kind="hist")