Scatterplots categóricos usando catplot() —#
0:00 min | Última modificación: Octubre 12, 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 |
Stripplot()#
[3]:
#
# Gráfico básico de puntos por categoría.
#
sns.catplot(
x="day",
y="total_bill",
data=tips,
kind='strip',
)
plt.show()

[4]:
#
# Efecto de jitter
#
sns.catplot(
x="day",
y="total_bill",
jitter=False,
data=tips,
kind='strip',
)
plt.show()

[5]:
#
# Gráfica para variables numéricas categóricas,
# modificando el orden del eje x.
#
sns.catplot(
x="size",
y="total_bill",
data=tips,
order=[2, 1, 3, 4, 5, 6],
kind='strip',
)
plt.show()

swarmplot()#
[6]:
#
# Gráfica kind="swarm" con separación por
# categorías.
#
sns.catplot(
x="day",
y="total_bill",
hue="sex",
kind="swarm",
data=tips,
)
plt.show()

[7]:
#
# La gráfica puede girarse con solo invertir las
# variables en los parámetros
#
sns.catplot(
x="total_bill",
y="day",
hue="time",
kind="swarm",
data=tips,
)
plt.show()

[8]:
#
# Separación por categorías
#
sns.catplot(
x="day",
y="total_bill",
hue="smoker",
col="time",
aspect=0.7,
kind="swarm",
data=tips,
)
plt.show()
