Relplots
Learn about data insights by customizing and styling relplots.
We'll cover the following...
Overview
Relplot stands for the relational plot that allows us to study the relationships between different variables. We can access both scatter plots and line plots within the relational plot. It’s built on top of seaborn’s FacetGrid
, allowing us to access FacetGrid
functionality within the relplot.
Accessing scatter plot within relplot
We’ve imported the titanic
dataset from the seaborn library and viewed the first five records using the pandas head()
method.
import pandas as pdimport seaborn as snsimport matplotlib.pyplot as pltsns.set_theme()titanic_df = sns.load_dataset('titanic')print(titanic_df.head())
Let’s draw a relplot using the sns.relplot()
function and specify x='age'
, y='fare'
, and hue ='class'
. The resulting plot is a scatter plot for the age
and fare
variables. Relplot shows a scatter plot by default.
sns.relplot(data = titanic_df , x= 'age', y='fare', hue='class')plt.savefig('output/graph.png') # save figure
Any parameter that we use with a scatter plot can also be used in a scatter plot called through a relplot. For ...