Histogramas básicos univariados con displot() —-#
0:00 min | Última modificación: Octubre 13, 2021 | [YouTube]
[1]:
import matplotlib.pyplot as plt
import seaborn as sns
[2]:
penguins = sns.load_dataset("penguins")
[3]:
sns.displot(
penguins,
x="flipper_length_mm",
kind="hist",
)
plt.show()

[4]:
#
# Modificación del tamñao de las barras
#
sns.displot(
penguins,
x="flipper_length_mm",
kind="hist",
binwidth=3,
)
plt.show()

[5]:
#
# Modificación de la cantidad de barras
#
sns.displot(
penguins,
x="flipper_length_mm",
kind="hist",
bins=20,
)
plt.show()

[6]:
#
# Histograma para variables categóricas
#
tips = sns.load_dataset("tips")
sns.displot(
tips,
kind="hist",
x="size",
)
plt.show()

[7]:
#
# Especificación de la ubicación de las barras
#
sns.displot(
tips,
x="size",
kind="hist",
bins=[1, 2, 3, 4, 5, 6, 7],
)
plt.show()

[8]:
#
# Especificación como variable discreta
#
sns.displot(
tips,
x="size",
kind="hist",
discrete=True,
)
plt.show()

[9]:
#
# Conteo de ocurrencias de una variable discreta
#
sns.displot(
tips,
x="day",
kind="hist",
shrink=0.8,
)
plt.show()
