Relational Plots in Seaborn – Scatter and Line Plots
Relational plots help you understand how two variables relate to each other.
In Seaborn, the two main functions for this are:
scatterplot()
– Shows the relationship between two continuous variables using points.lineplot()
– Shows trends or patterns between variables using lines.
Both functions are part of Seaborn’s relational plotting category.
When to Use Scatter vs Line
- Scatter Plot: Best for examining how one variable changes with another without assuming continuity (e.g.,
height
vsweight
). - Line Plot: Best for showing trends over an ordered sequence (e.g., time series data).
Basic Scatter Plot
Simple Scatter Plot
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
sns.scatterplot(data=tips, x="total_bill", y="tip")
plt.show()
Basic Line Plot
Simple Line Plot
fmri = sns.load_dataset("fmri")
sns.lineplot(data=fmri, x="timepoint", y="signal")
plt.show()
Relational plots can be further customized with parameters like hue
, style
, and size
to add categories, patterns, or variable-sized points.
You’ll explore these enhancements in the Jupyter Notebook on the right side of the screen.
Want to learn more?
Join CodeFriends Plus membership or enroll in a course to start your journey.