Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Catplot | Categorical Plot Types
Deep Dive into the seaborn Visualization

book
Catplot

Note

catplot = FacetGrid + stripplot/swarmplot/boxplot/violinplot/barplot/pointplot

The catplot function provides a new framework giving access to several types of plots that show a relationship between a numerical variable and one or more categorical variables, like boxplot, stripplot and so on.

carousel-imgcarousel-imgcarousel-imgcarousel-imgcarousel-imgcarousel-imgcarousel-imgcarousel-imgcarousel-img

Note

Scroll down to see the full plot when you cope with the task!

Task

Swipe to start coding

  1. Set the 'white' style with the 'aliceblue' axes.facecolor.
  2. Create the catplot using the seaborn library:
  • Set the x parameter equals the 'species';
  • Set the y parameter equals the 'body_mass_g';
  • Set the hue parameter equals the 'sex';
  • Set the row parameter equals the 'island';
  • Set the 'viridis' palette;
  • Set the alpha parameter equals 0.6;
  • Disable the legend_out.

Solution

import warnings

# Ignore all warnings
warnings.filterwarnings('ignore')

# Importing libraries needed
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

# Reading the file
df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/66ba0c8e-8422-413c-b7e1-74bd24c61656/penguins.csv')

# Set the 'white' style with the 'aliceblue' facecolor
sns.set_style('white', {'axes.facecolor' : 'aliceblue'})
# Create a catplot
sns.catplot(# Set the x
x = 'species',
# Set the y
y = 'body_mass_g',
# Set the hue
hue = 'sex',
# Set the row
row = 'island',
# Set the palette
palette = 'viridis',
# Set the alpha
alpha = 0.6,
# Set the legend_out
legend_out = False,
# Setting the data
data = df)

# Displaying the plot
plt.show()

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 3. Chapter 8
single

single

import warnings

# Ignore all warnings
warnings.filterwarnings('ignore')

# Importing libraries needed
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

# Reading the file
df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/66ba0c8e-8422-413c-b7e1-74bd24c61656/penguins.csv')

# Set the 'white' style with the 'aliceblue' facecolor
___(___, {'___.facecolor' : '___'})
# Create a catplot
___(# Set the x
___,
# Set the y
y = '___',
# Set the hue
___,
# Set the row
___ = '___',
# Set the palette
___,
# Set the alpha
___,
# Set the legend_out
legend_out = ___,
# Setting the data
data = df)

# Displaying the plot
plt.show()

Ask AI

expand

Ask AI

ChatGPT

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

some-alt