Scatter Plots in Pandas & Seaborn – Best Practices for Relationship Analysis 2026
Scatter plots are the best way to visualize the relationship between two numerical variables. In 2026, combining Pandas’ quick .plot.scatter() with Seaborn’s scatterplot() and regplot() gives you both fast exploration and insightful, publication-quality visualizations.
TL;DR — Recommended Scatter Plot Methods
df.plot.scatter(x, y)– Quick Pandas scattersns.scatterplot()– Beautiful plots with hue and sizesns.regplot()– Scatter with regression line
1. Basic Scatter Plot with Pandas
import pandas as pd
import matplotlib.pyplot as plt
# Create a small demo file so this example runs as-is
# (in your project, sales_data.csv is your real export)
import numpy as np
rng = np.random.default_rng(42)
n = 60
pd.DataFrame({
"order_date": pd.date_range("2026-01-01", periods=n, freq="3D"),
"customer_id": rng.integers(101, 121, n),
"customer_name": rng.choice([" ana", "ben ", "chen", "dana"], n),
"product_id": rng.integers(1, 9, n),
"region": rng.choice(["North", "South", "East", "West"], n),
"category": rng.choice(["Electronics", "Computers", "Books", "Home"], n),
"payment_method": rng.choice(["card", "cash", "wallet"], n),
"segment": rng.choice(["consumer", "business"], n),
"quantity": rng.integers(1, 6, n),
"amount": rng.uniform(50, 2500, n).round(2),
"discount": rng.choice([0.0, 0.05, 0.1, 0.2], n),
}).assign(
price=lambda d: (d["amount"] / d["quantity"]).round(2),
profit=lambda d: (d["amount"] * rng.uniform(0.05, 0.3, n)).round(2),
).assign(
ship_date=lambda d: d["order_date"] + pd.Timedelta(days=2),
status=lambda d: np.where(d["amount"] > 2000, "priority", "standard"),
).to_csv("sales_data.csv", index=False)
df = pd.read_csv("sales_data.csv")
df.plot.scatter(
x="quantity",
y="amount",
figsize=(10, 6),
alpha=0.6,
s=50, # marker size
color="royalblue"
)
plt.title("Relationship between Quantity and Sales Amount")
plt.xlabel("Quantity Sold")
plt.ylabel("Sales Amount")
plt.grid(True, alpha=0.3)
plt.show()
2. Advanced Scatter Plot with Seaborn
import seaborn as sns
plt.figure(figsize=(11, 7))
sns.scatterplot(
data=df,
x="quantity",
y="amount",
hue="region", # Color by category
size="profit", # Size by another variable
alpha=0.7,
palette="viridis"
)
plt.title("Quantity vs Sales Amount by Region")
plt.xlabel("Quantity Sold")
plt.ylabel("Sales Amount")
plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left')
plt.show()
3. Scatter Plot with Regression Line (Very Useful)
plt.figure(figsize=(10, 6))
sns.regplot(
data=df,
x="quantity",
y="amount",
scatter_kws={"alpha": 0.6},
line_kws={"color": "red"}
)
plt.title("Quantity vs Sales Amount with Regression Line")
plt.show()
4. Best Practices in 2026
- Use
alpha=0.6or lower to handle overplotting when you have many points - Use
huein Seaborn to show categorical grouping - Use
sizeparameter to encode a third variable - Use
sns.regplot()when you want to see the trend line - Always add clear titles and axis labels
- For very large datasets, consider sampling or using
hexbininstead
Scatter Plots and Relationships
A scatter plot puts one numeric variable on each axis so you can see whether they move together. Look for direction, strength, curved patterns, clusters and outliers before computing a correlation coefficient.
Colour by a category with hue to see whether groups behave differently, and lower alpha when points overlap. A correlation number alone can hide curves and outliers, so the plot and the statistic should always go together.
Worked Example: Advertising and Sales
We simulate advertising spend and sales for two channels, then plot and correlate them.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
rng = np.random.default_rng(7)
ad = rng.uniform(1, 10, 80)
channel = np.where(np.arange(80) < 40, "online", "print")
sales = np.where(channel == "online", 5 * ad, 2 * ad) + rng.normal(0, 3, 80)
df = pd.DataFrame({"ad_spend": ad, "sales": sales, "channel": channel})
print(df.groupby("channel")[["ad_spend", "sales"]].corr().round(2))
fig, ax = plt.subplots(figsize=(6, 4))
sns.scatterplot(data=df, x="ad_spend", y="sales", hue="channel", alpha=0.7, ax=ax)
fig.tight_layout()
Both channels show positive relationships, but the online points rise much more steeply. Splitting by hue makes that difference visible, while a single overall correlation would blur it.
Practical Tips
With thousands of points, scatter plots can turn into a solid blob. Lower alpha, use smaller markers, sample the data, or switch to a hexbin or two-dimensional histogram so density becomes visible. Adding a regression line with seaborn regplot can summarise the trend, but always keep the raw points in view so outliers and curves are not hidden behind a straight line.
Common Mistakes
- Treating correlation as proof of causation.
- Ignoring overplotting in large datasets.
- Using scatter plots for categorical axes.
- Reporting one overall correlation when groups differ.
Quick Summary
- Scatter plots show relationships between two numbers.
- Use hue to compare groups.
- Lower alpha for overlapping points.
- Pair the plot with a correlation check.
Conclusion
Scatter plots are essential for understanding relationships between two numerical variables. In 2026, start with Pandas .plot.scatter() for quick checks, then use Seaborn’s scatterplot() and regplot() for deeper insights and better visuals. Proper use of hue, size, and alpha will make your scatter plots much more informative and professional.
Next steps:
- Create scatter plots to explore the relationship between quantity and amount, and between profit and sales in your current dataset