Personalización de gráficos de regresión usando lmplot() —#

  • 0:00 min | Última modificación: Octubre 13, 2021 | [YouTube]

[1]:
import matplotlib.pyplot as plt
import seaborn as sns
[2]:
tips = sns.load_dataset("tips")

tips.head()
[2]:
total_bill tip sex smoker day time size
0 16.99 1.01 Female No Sun Dinner 2
1 10.34 1.66 Male No Sun Dinner 3
2 21.01 3.50 Male No Sun Dinner 3
3 23.68 3.31 Male No Sun Dinner 2
4 24.59 3.61 Female No Sun Dinner 4
[3]:
#
# Tamaño
#
f, ax = plt.subplots(figsize=(5, 6))
sns.regplot(
    x="total_bill",
    y="tip",
    data=tips,
    ax=ax,
)
plt.show()
../../_images/02_seaborn_notebooks_5-53_regression_formato_3_0.png
[4]:
#
# Número fijo de columnas
#
sns.lmplot(
    x="total_bill",
    y="tip",
    col="day",
    data=tips,
    col_wrap=2,
    height=4,
)

plt.show()
../../_images/02_seaborn_notebooks_5-53_regression_formato_4_0.png
[5]:
#
# Relación de aspecto de la gráfica
#
sns.lmplot(
    x="total_bill",
    y="tip",
    col="day",
    data=tips,
    aspect=0.5,
)

plt.show()
../../_images/02_seaborn_notebooks_5-53_regression_formato_5_0.png