학습 자료

Grouping and Hue for Comparisons in Seaborn

One of Seaborn’s most powerful features is its ability to easily compare subgroups within a dataset using the hue parameter.
By adding hue, you can split data into categories and display them with different colors — making comparisons more intuitive.


Why Hue is Useful

  • Adds another layer of information without creating separate plots.
  • Helps identify patterns and differences between categories.
  • Works across most Seaborn functions like barplot, scatterplot, and lineplot.

Example – Comparing Categories in a Scatterplot

Scatterplot with Hue
import seaborn as sns import matplotlib.pyplot as plt # Sample dataset tips = sns.load_dataset("tips") # Scatterplot with hue for gender sns.scatterplot(data=tips, x="total_bill", y="tip", hue="sex") plt.title("Total Bill vs Tip by Gender") plt.show()
  • hue="sex" automatically assigns different colors for male and female groups.
  • Seaborn adds a legend by default to indicate which color corresponds to which group.

Pro Tip

When using hue, you can also adjust palette for custom color schemes:

Custom Color Palette
sns.scatterplot(data=tips, x="total_bill", y="tip", hue="sex", palette="Set2")

In the next Jupyter notebook, you’ll explore how to use hue in different chart types and experiment with your own datasets.

Quiz
0 / 1

How to use the hue parameter to visualize subgroups within your data in Seaborn?

In a Seaborn scatterplot, the hue parameter is used to differentiate within the data.
Subgroups
Titles
Axes
Labels

학습 자료

AI 튜터

디자인

업로드

수업 노트

즐겨찾기

도움말