Visualization with Cat Plots
Learn how to visualize categorical data through a cat plot.
We'll cover the following...
Overview
The cat plot stands for the categorical plot, which represents the relationship between variables. We can access all the categorical plots, such as bar, box, violin, swarm, and so on. It’s built on top of seaborn’s FacetGrid
, which means we can have multiple plots within the same plot. The default cat plot is a strip plot.
Plotting cat plots
We’ve already imported the required libraries and saved the titanic
dataset in the titanic_df
DataFrame (after removing the null values). Let’s get started with the visualizations. We call the sns.catplot()
function and pass x='age'
:
sns.catplot(x ='age', data = titanic_df) # default strip plotplt.savefig('output/graph.png')
By default, the cat plot shows a strip plot. However, we can switch the plot by specifying it in the kind
parameter in the sns.catplot()
function. For example, let’s draw a violin plot through a cat plot by specifying kind='violin'
. We can access all the categorical plots by specifying them in the kind
...