Relplots

Learn about data insights by customizing and styling relplots.

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.

Press + to interact
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
sns.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.

Press + to interact
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 ...