Relational Plots in Seaborn – Scatter and Line Plots
Relational plots help you understand how two variables are related.
In Seaborn, the two main functions for this are:
scatterplot()
: Displays the relationship between two continuous variables using points.lineplot()
: Shows trends or patterns between variables using lines.
Both are part of Seaborn's relational plotting tools.
When to Use Scatter vs. Line
- Scatter plot: Use when you want to explore how one variable changes with another without assuming a continuous relationship (e.g.,
height
vs.weight
). - Line plot: Use when you want to show trends over an ordered sequence, such as 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.title("Scatter Plot of Total Bill vs Tip") plt.show()
Basic Line Plot
Simple Line Plot
fmri = sns.load_dataset("fmri") sns.lineplot(data=fmri, x="timepoint", y="signal") plt.title("Line Plot of Signal over Time") plt.show()
You can customize relational plots using parameters like hue
, style
, and size
to add categories, patterns, or variable-sized points.
Quiz
0 / 1
Which Seaborn function is best suited for visualizing trends over an ordered sequence?
scatterplot()
pairplot()
lineplot()
barplot()
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help