Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Mastering the Categorical Interface | Section
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Statistical Visualization with Seaborn

bookMastering the Categorical Interface

The catplot (categorical plot) is the general figure-level interface that gives you access to every categorical plot we've learned so far (stripplot, boxplot, violinplot, barplot, etc.).

Why use Catplot?

Just like displot, the main superpower of catplot is faceting. You can easily split your analysis into multiple subplots based on a categorical variable using row and col.

Key Parameters

  • kind: the name of the plot type you want to draw. Defaults to 'strip', but you can set it to:
    • 'swarm', 'box', 'violin', 'boxen', 'point', 'bar', 'count'.
  • row / col: variables that define subsets to plot on different facets (subplots);
  • legend_out: if True (default), the legend is drawn outside the plot area to prevent it from covering data.

Live Example

Here we create a Boxplot for each time of day (Lunch/Dinner) automatically using col.

123456789101112131415161718
import seaborn as sns import matplotlib.pyplot as plt # Load dataset df = sns.load_dataset('tips') # Create a grid of boxplots sns.catplot( data=df, hue='day', x='day', y='total_bill', col='time', # Split into 2 columns (Lunch/Dinner) kind='box', # Draw boxplots palette='Set3' ) plt.show()
copy
Task

Swipe to start coding

Visualize the body mass of penguins across different islands and species.

  1. Set the style to 'white'. Customize the background color to 'aliceblue' ('axes.facecolor').
  2. Create a catplot using the penguins dataset (df):
    • Map 'species' to x and 'body_mass_g' to y.
    • Color points by 'sex' using hue.
    • Split the plot into rows based on the 'island' variable using row.
    • Use the 'viridis' palette.
    • Set point transparency alpha to 0.6.
    • Move the legend inside the plot by setting legend_out=False.
  3. Display the plot.

Solution

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 15
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

close

bookMastering the Categorical Interface

Swipe to show menu

The catplot (categorical plot) is the general figure-level interface that gives you access to every categorical plot we've learned so far (stripplot, boxplot, violinplot, barplot, etc.).

Why use Catplot?

Just like displot, the main superpower of catplot is faceting. You can easily split your analysis into multiple subplots based on a categorical variable using row and col.

Key Parameters

  • kind: the name of the plot type you want to draw. Defaults to 'strip', but you can set it to:
    • 'swarm', 'box', 'violin', 'boxen', 'point', 'bar', 'count'.
  • row / col: variables that define subsets to plot on different facets (subplots);
  • legend_out: if True (default), the legend is drawn outside the plot area to prevent it from covering data.

Live Example

Here we create a Boxplot for each time of day (Lunch/Dinner) automatically using col.

123456789101112131415161718
import seaborn as sns import matplotlib.pyplot as plt # Load dataset df = sns.load_dataset('tips') # Create a grid of boxplots sns.catplot( data=df, hue='day', x='day', y='total_bill', col='time', # Split into 2 columns (Lunch/Dinner) kind='box', # Draw boxplots palette='Set3' ) plt.show()
copy
Task

Swipe to start coding

Visualize the body mass of penguins across different islands and species.

  1. Set the style to 'white'. Customize the background color to 'aliceblue' ('axes.facecolor').
  2. Create a catplot using the penguins dataset (df):
    • Map 'species' to x and 'body_mass_g' to y.
    • Color points by 'sex' using hue.
    • Split the plot into rows based on the 'island' variable using row.
    • Use the 'viridis' palette.
    • Set point transparency alpha to 0.6.
    • Move the legend inside the plot by setting legend_out=False.
  3. Display the plot.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 15
single

single

some-alt