MulaiMulai sekarang secara 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.

Latihan ini adalah bagian dari kursus

Introduction to Data Visualization with Seaborn

Lihat Kursus

Petunjuk latihan

  • 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.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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()
Edit dan Jalankan Kode