IniziaInizia gratis

Hue and count plots

Let's continue exploring our dataset from students in secondary school by looking at a new variable. The "school" column indicates the initials of which school the student attended - either "GP" or "MS".

In the last exercise, we created a scatter plot where the plot points were colored based on whether the student lived in an urban or rural area. How many students live in urban vs. rural areas, and does this vary based on what school the student attends? Let's make a count plot with subgroups to find out.

Questo esercizio fa parte del corso

Introduction to Data Visualization with Seaborn

Visualizza il corso

Istruzioni dell'esercizio

  • Fill in the palette_colors dictionary to map the "Rural" location value to the color "green" and the "Urban" location value to the color "blue".
  • Create a count plot with "school" on the x-axis using the student_data DataFrame.
    • Add subgroups to the plot using "location" variable and use the palette_colors dictionary to make the location subgroups green and blue.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

# Import Matplotlib and Seaborn
import matplotlib.pyplot as plt
import seaborn as sns

# Create a dictionary mapping subgroup values to colors
palette_colors = {____: "green", ____: "blue"}

# Create a count plot of school with location subgroups




# Display plot
plt.show()
Modifica ed esegui il codice