Mastering 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: ifTrue(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.
123456789101112131415161718import 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()
Swipe to start coding
Visualize the body mass of penguins across different islands and species.
- Set the style to
'white'. Customize the background color to'aliceblue'('axes.facecolor'). - Create a catplot using the
penguinsdataset (df):- Map
'species'toxand'body_mass_g'toy. - Color points by
'sex'usinghue. - Split the plot into rows based on the
'island'variable usingrow. - Use the
'viridis'palette. - Set point transparency
alphato0.6. - Move the legend inside the plot by setting
legend_out=False.
- Map
- Display the plot.
Solution
Thanks for your feedback!
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 4.55
Mastering 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: ifTrue(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.
123456789101112131415161718import 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()
Swipe to start coding
Visualize the body mass of penguins across different islands and species.
- Set the style to
'white'. Customize the background color to'aliceblue'('axes.facecolor'). - Create a catplot using the
penguinsdataset (df):- Map
'species'toxand'body_mass_g'toy. - Color points by
'sex'usinghue. - Split the plot into rows based on the
'island'variable usingrow. - Use the
'viridis'palette. - Set point transparency
alphato0.6. - Move the legend inside the plot by setting
legend_out=False.
- Map
- Display the plot.
Solution
Thanks for your feedback!
single