Violinplots 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 |
[3]:
#
# Gráfica básica de violin por categoría.
#
sns.catplot(
x="total_bill",
y="day",
hue="sex",
kind="violin",
data=tips,
)
plt.show()
[4]:
#
# Modificación de los parámetros.
#
sns.catplot(
x="total_bill",
y="day",
hue="sex",
kind="violin",
bw=0.15,
cut=0,
data=tips,
)
plt.show()
[5]:
#
# Construcción de una gráfica comparativa usando
# split.
#
sns.catplot(
x="day",
y="total_bill",
hue="sex",
kind="violin",
split=True,
data=tips,
)
plt.show()
[ ]:
#
# Modificación de la visualización de los datos
# al interior de las figuras
#
sns.catplot(
x="day",
y="total_bill",
hue="sex",
kind="violin",
inner="stick",
split=True,
palette="pastel",
data=tips,
)
plt.show()
[ ]:
#
# Combinación de swarm con violin
#
g = sns.catplot(
x="day",
y="total_bill",
kind="violin",
inner=None,
data=tips,
)
sns.swarmplot(
x="day",
y="total_bill",
color="k",
size=3,
data=tips,
ax=g.ax,
)
plt.show()