Facetas, hue y style
Dividir los gráficos por categoría.
Facetas, hue y style es una lección gratuita de Data Science Academy en CoddyKit. Esta es la lección 4 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Data Science Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Data Science Academy incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
One Chart, Many Slices
Sometimes one plot hides too much. Faceting splits your data into a grid of small charts, one per category, so each group gets its own view.
Encode Groups With hue
The lightest way to compare groups is color. hue maps a category to colors inside a single plot, no extra panels needed.
sns.scatterplot(data=df, x="x", y="y", hue="group")Split Into Columns
To break groups into separate panels, use a figure-level plot with col. Each category becomes its own side-by-side chart.
sns.relplot(data=df, x="x", y="y", col="group")Split Into Rows Too
Pair col with row to build a full grid. One variable spreads across columns while another stacks down the rows.
sns.relplot(data=df, x="x", y="y", col="region", row="year")Figure-Level vs Axes-Level
Faceting needs figure-level functions like relplot, displot, and catplot. The plain plots such as scatterplot live inside a single panel.
Wrap Long Facet Rows
Many categories make an endless row. col_wrap tells seaborn how many panels to allow before starting a new line.
sns.relplot(data=df, x="x", y="y", col="city", col_wrap=3)Style Encodes Without Color
Beyond color, style maps a category to marker shapes or dashed lines, helping when prints are black and white.
sns.lineplot(data=df, x="x", y="y", style="device")Pick a Color Palette
Swap the colors with palette. Choose a vivid set for distinct groups or a gradient for values that go from low to high.
sns.scatterplot(data=df, x="x", y="y", hue="group", palette="viridis")Set the Overall Look
One call restyles every chart at once. set_theme controls the background, gridlines, and default palette for the session.
sns.set_theme(style="darkgrid", palette="muted")Combine hue and Facets
You can layer them: color within each panel and split panels by another field. Just avoid encoding so much that the message gets lost.
sns.relplot(data=df, x="x", y="y", hue="sex", col="day")Less Is Often More
Every extra hue, style, and facet adds load for the reader. Aim for the simplest view that still answers the question.
Quick Check
You want each category drawn in its own separate panel.
Recap: Encode, Facet, Style
You now layer information with hue and style, split groups using facets, and theme it all cleanly, while keeping the chart easy to read. 🎨
Preguntas frecuentes
¿La lección «Facetas, hue y style» es gratis?
Sí — el texto completo de «Facetas, hue y style» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Data Science Academy, actualiza a CoddyKit PRO. El curso de Data Science Academy incluye 4 lecciones en total.
¿Qué aprenderé en «Facetas, hue y style»?
Dividir los gráficos por categoría. Practicas Data Science Academy con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar Data Science Academy?
No se requiere experiencia previa. Data Science Academy en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 4 de 4.
¿Cuánto tiempo toma la lección «Facetas, hue y style»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de Data Science Academy?
Sí. Cada lección de Data Science Academy incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- Por qué seaborn en lugar de matplotlib sin procesar
- Distribuciones: hist, kde y box
- Relaciones: dispersión y líneas
- Facetas, hue y style