Data VisualizationNot Started
Scatter Plots
Visualize the relationship between two continuous variables
0%
Knowledge0%
Learn & DrillFluency0%
Drill & SpeedRetention0%
Mastery & ReviewConfidence0%
All modesFree tier: read the explanation here. Upgrade to Pro for Drills, Speed challenges & Mastery badges.
UpgradeKnowledge
Fluency
Retention
Knowledge Debt detected
You can study this freely — but your score may plateau if these foundations have gaps. The Mastery badge requires them to be solid.
Explanation
Scatter plots show how two numerical variables relate to each other. Each point = one observation.
python
fig, ax = plt.subplots()
ax.scatter(df['height'], df['weight'],
alpha=0.5, color='steelblue', s=30)
ax.set_xlabel('Height (cm)')
ax.set_ylabel('Weight (kg)')
ax.set_title('Height vs Weight')
plt.show()Key parameters:
s— marker size (default 20)c— color (can be an array to color-code by a third variable)alpha— transparency (essential for overlapping points)cmap— colormap when c is numeric ('viridis', 'coolwarm', 'Reds')
Color by a third variable:
python scatter = ax.scatter(x, y, c=df['age'], cmap='viridis', s=40) fig.colorbar(scatter, label='Age')
When to use scatter vs line:
- Scatter: no inherent order between points (height vs weight)
- Line: points have a meaningful order (time series)
Examples
Color-coded scatter plot
c= accepts a list of colors to color each point individually
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(0)
n = 100
x = np.random.rand(n) * 100 # study hours × 10
y = x * 0.8 + np.random.randn(n) * 10 # scores
grade = np.where(y > 70, 'Pass', 'Fail')
colors = np.where(y > 70, 'green', 'red')
fig, ax = plt.subplots()
ax.scatter(x, y, c=colors, alpha=0.6)
ax.set_xlabel('Study Hours')
ax.set_ylabel('Score')
ax.set_title('Study Hours vs Score')How well did you understand this?
Next in Data Visualization
seaborn vs matplotlib